Use a MaskedTextBox, it has a built in phone number mask I believe.
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 enteredPrivate 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
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
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]
||Excision|| (04-26-2012)
yep that's an alternative but Is it possible to code it?
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
What it do: When yo have entered the 10 Numbers.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)
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:
to use just enter 10 or 11 digits numbersCode: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
it will be transformed once the user move out the textbox
@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 properlyCode:Private Sub txtPhone_LostFocus(sender As Object, e As System.EventArgs) Handles txtPhone.LostFocus Mask_Phone(txtPhone.Text) End Sub
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.