-
Format Phone Number
I am trying to check and make sure that the User has entered a proper format Phone number
555-555-5555
or
555-5555
i tried to use the
Code:
textbox.text<>format(textbox.text,"###-####)
and
Code:
textbox.text<>format(textbox.text,"###-###-####)
but if i enter 1234-55
it says that it is valid. How can i make sure that all the pos-holders are filled
thanks
-
<?>
you would do better to use the MaskeditControl
with it you specify a mask ###-###-####
and that is what you get
or your just allow the user to enter 9 digits and format it in your code.
If len(text1.text) = 9 then
myVariable = format(text1.text,"###-###-####")
else
msgbox "Sorry, you need 9 digits
Endif
as an additive, I personally would store my phone numbers as 9 digit numbers without the - I use a masked edit box but I don't store 905-555-6666 I store 9055556666
-
here is some code I wrote to check for validation for a 7 digit phone number if you need nine, just change the position of the "-" and add more cases
Code:
Private Sub Command1_Click()
Dim Bln(7) As Boolean
Dim TheLetter As String
Dim TheWhole As Boolean
TheWhole = True
For i = 1 To Len(Text1)
TheLetter = Mid$(Text1, i, 1)
Select Case i
Case 1
If IsNumeric(Val(TheLetter)) Then
Bln(i - 1) = True
End If
Case 2
If IsNumeric(Val(TheLetter)) Then
Bln(i - 1) = True
End If
Case 3
If IsNumeric(Val(TheLetter)) Then
Bln(i - 1) = True
End If
Case 4
If TheLetter = "-" Then
Bln(i - 1) = True
End If
Case 5
If IsNumeric(Val(TheLetter)) Then
Bln(i - 1) = True
End If
Case 6
If IsNumeric(Val(TheLetter)) Then
Bln(i - 1) = True
End If
Case 7
If IsNumeric(Val(TheLetter)) Then
Bln(i - 1) = True
End If
Case 8
If IsNumeric(Val(TheLetter)) Then
Bln(i - 1) = True
End If
End Select
Next
For i = 0 To 7
If Bln(i) = False Then
TheWhole = False
End If
Next
If TheWhole = False Then
MsgBox "wrong format"
End If
End Sub
-
Or even better, case 1 to 8!
-
we need to skip 4, so 1 to 8 wouldnt work.
-
Code:
IF textbox.text Like "###-###-####" or textbox.text like "###-####" then Msgbox "proper number"