Results 1 to 7 of 7
  1. #1
    franzyx's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Location
    Right There.
    Posts
    607
    Reputation
    7
    Thanks
    73
    My Mood
    Fine

    Masking A Phone Number

    I'm trying to make a textbox for telephone Number input that on text changed if user enter 3 nubmer it will be (###) and the final result should look like this (###) ###-####

    i tried by myself with a lil bit of success but it doesnt work properly if the user need the edit or erase the number and retype
    Private Sub txtPhone_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtPhone.TextChanged

    If txtPhone.Text.Length = 3 And IsNumeric(txtPhone.Text) And Val(txtPhone.Text) > 100 Then
    txtPhone.Text = "(" & txtPhone.Text & ")" & " "
    txtPhone.SelectionStart = 6

    ElseIf Trim(txtPhone.Text).Length = 9 Then
    txtPhone.Text = txtPhone.Text & "-"
    txtPhone.SelectionStart = 11
    End If

    End Sub
    This is just my security maeasure to make sure only numbers are entered

    Private Sub txtPhone_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPhone.KeyPress

    If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = "." Or e.KeyChar = ControlChars.Back) Then
    e.Handled = True
    End If

    End Sub

    Thanks in advance for any help

  2. #2
    master131's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    Melbourne, Australia
    Posts
    8,858
    Reputation
    3438
    Thanks
    101,669
    My Mood
    Breezy
    Use a MaskedTextBox, it has a built in phone number mask I believe.
    Donate:
    BTC: 1GEny3y5tsYfw8E8A45upK6PKVAEcUDNv9


    Handy Tools/Hacks:
    Extreme Injector v3.7.3
    A powerful and advanced injector in a simple GUI.
    Can scramble DLLs on injection making them harder to detect and even make detected hacks work again!

    Minion Since: 13th January 2011
    Moderator Since: 6th May 2011
    Global Moderator Since: 29th April 2012
    Super User/Unknown Since: 23rd July 2013
    'Game Hacking' Team Since: 30th July 2013

    --My Art--
    [Roxas - Pixel Art, WIP]
    [Natsu - Drawn]
    [Natsu - Coloured]


    All drawings are coloured using Photoshop.

    --Gifts--
    [Kyle]

  3. The Following User Says Thank You to master131 For This Useful Post:

    ||Excision|| (04-26-2012)

  4. #3
    franzyx's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Location
    Right There.
    Posts
    607
    Reputation
    7
    Thanks
    73
    My Mood
    Fine
    yep that's an alternative but Is it possible to code it?

  5. #4
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Quote Originally Posted by franzyx View Post
    yep that's an alternative but Is it possible to code it?
    Yes, it is possible.

  6. #5
    JcbyFong's Avatar
    Join Date
    Apr 2012
    Gender
    male
    Posts
    2
    Reputation
    10
    Thanks
    0
    yep that's an alternative


  7. #6
    Jorndel's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    Norway
    Posts
    8,676
    Reputation
    905
    Thanks
    19,113
    My Mood
    Angelic
    Quote Originally Posted by franzyx View Post
    I'm trying to make a textbox for telephone Number input that on text changed if user enter 3 nubmer it will be (###) and the final result should look like this (###) ###-####

    i tried by myself with a lil bit of success but it doesnt work properly if the user need the edit or erase the number and retype


    This is just my security maeasure to make sure only numbers are entered



    Thanks in advance for any help
    I would suggest to look on the MaskedTextbox.
    It would mostly like solve it for you.

    Well, I gave it a try. (I didn't but so much work in it)
    so the code, is very nooby

    Code:
    If TextBox1.Text.Length = 11 Then TextBox1.Text = "(" + TextBox1.Text(0) + TextBox1.Text(2) + TextBox1.Text(3) + ")" + TextBox1.Text(4) + TextBox1.Text(5) + TextBox1.Text(6) + "-" + TextBox1.Text(7) + TextBox1.Text(8) + TextBox1.Text(9) + TextBox1.Text(10)
    What it do: When yo have entered the 10 Numbers.
    It will transform the style into the one you wanted.
    (Suppose I go to bed now :P)

     
    Contributor 01.27.2012 - N/A
    Donator 07-17-2012 - Current
    Editor/Manager 12-16-12 - N/A
    Minion 01-10-2013 - 07.17.13
    Former Staff 09-20-2012 - 01-10-2013 / 07-17-2013 - Current
    Cocksucker 20-04-2013 - N/A

  8. #7
    franzyx's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Location
    Right There.
    Posts
    607
    Reputation
    7
    Thanks
    73
    My Mood
    Fine
    Quote Originally Posted by Jorndel View Post
    I would suggest to look on the MaskedTextbox.
    It would mostly like solve it for you.

    Well, I gave it a try. (I didn't but so much work in it)
    so the code, is very nooby

    Code:
    If TextBox1.Text.Length = 11 Then TextBox1.Text = "(" + TextBox1.Text(0) + TextBox1.Text(2) + TextBox1.Text(3) + ")" + TextBox1.Text(4) + TextBox1.Text(5) + TextBox1.Text(6) + "-" + TextBox1.Text(7) + TextBox1.Text(8) + TextBox1.Text(9) + TextBox1.Text(10)
    What it do: When yo have entered the 10 Numbers.
    It will transform the style into the one you wanted.
    (Suppose I go to bed now :P)

    ahh i decided to make a functions instead for me i think works better

    function:
    Code:
    Private Sub Mask_Phone(ByVal BPhone As String)
            If Len(Trim(BPhone)) = 10 Then
                BPhone = "(" & Strings.Left(BPhone, 3) & ")" & " " &
                    Strings.Mid(BPhone, 4, 3) & "-" & Strings.Right(BPhone, 4)
            ElseIf BPhone.Length = 11 Then
                BPhone = Strings.Left(BPhone, 1) & "(" & Strings.Mid(BPhone, 2, 3) & ")" & " " &
                   Strings.Mid(txtPhone.Text, 5, 3) & "-" & Strings.Right(txtPhone.Text, 4)
            End If
            txtPhone.Text = BPhone
        End Sub
    to use just enter 10 or 11 digits numbers
    it will be transformed once the user move out the textbox
    Code:
     Private Sub txtPhone_LostFocus(sender As Object, e As System.EventArgs) Handles txtPhone.LostFocus
            Mask_Phone(txtPhone.Text)
        End Sub
    @Jorndel but your code also works just that if the user try to edits or remove it will get nasty i mean it will not work properly
    Thanks guys ima just give for now fi manage to make a good masked phone number by code i will post it
    Last edited by franzyx; 04-21-2012 at 09:07 PM.

Similar Threads

  1. Nexons phone number
    By Tall kiwi in forum Combat Arms Discussions
    Replies: 24
    Last Post: 09-15-2009, 07:38 PM
  2. Replies: 8
    Last Post: 05-27-2009, 07:10 PM
  3. need phone number for korea warrock?
    By b0wsersr in forum WarRock Korea Hacks
    Replies: 0
    Last Post: 11-06-2008, 02:15 PM
  4. Obama's Phone Number Leak.
    By Jo33333 in forum General
    Replies: 16
    Last Post: 11-05-2008, 08:30 AM
  5. Nexon's Phone Number
    By KyleForrest in forum Combat Arms Hacks & Cheats
    Replies: 17
    Last Post: 11-05-2008, 04:59 AM