|
-
Aug 16th, 2000, 09:56 AM
#1
Thread Starter
Lively Member
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
VB 6 Professional Edition
-
Aug 16th, 2000, 10:28 AM
#2
_______
<?>
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
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Aug 16th, 2000, 10:32 AM
#3
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
-
Aug 16th, 2000, 03:51 PM
#4
Fanatic Member
Or even better, case 1 to 8!
-
Aug 16th, 2000, 03:59 PM
#5
we need to skip 4, so 1 to 8 wouldnt work.
-
Aug 16th, 2000, 04:16 PM
#6
transcendental analytic
Code:
IF textbox.text Like "###-###-####" or textbox.text like "###-####" then Msgbox "proper number"
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|