by Doongoor Navindresingh (2 Submissions)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sat 28th April 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)
This function validates fax or phone numbers.
Dim strCurrentChar As String
Dim lngIndex As Long
ValidatePhone = True
strPhone = Trim(strPhone)
'If Phone is not at least (012)345-6789 long
If Len(strPhone) <> 13 Then GoTo Fail_Validation
strCurrentChar = Left(strPhone, 1)
If strCurrentChar <> "(" Then GoTo Fail_Validation
strCurrentChar = Mid(strPhone, 5, 1)
If strCurrentChar <> ")" Then GoTo Fail_Validation
strCurrentChar = Mid(strPhone, 9, 1)
If strCurrentChar <> "-" Then GoTo Fail_Validation
For lngIndex = 1 To Len(strPhone)
strCurrentChar = Mid(strPhone, lngIndex, 1)
Select Case Asc(strCurrentChar)
Case 1 To 31, 33 To 39, 42, 44, 46, 58 To 255
GoTo Fail_Validation
End Select
Next lngIndex
ValidatePhone_Exit:
Exit Function
Fail_Validation:
ValidatePhone = False
GoTo ValidatePhone_Exit
End Function