Create a function in a module to verify phone numbers in accordance with the North American Numbering Plan (NANP) rules. You should be able to pass in a phone number and the function will verify whether the phone number is valid. There are many ways to do this. My suggestion would be to have the function return a string value. If the string value returned is an empty string then the phone number is valid. If the phone number is invalid have the function return the string with the reason why the phone number is invalid. Below are some sample invalid phone numbers, representing each class of number:
Verify a specific phone number manually entered against NANP rules
Use a MakedTexbox for the phone number entry. Don’t forget to strip the added characters “()-
must use option strict on and Module that holds a function
there will be a box for the phone number, a button to validate, a button to close
no Hungarian notation
---I need to call the module function on my form
What I have tried:
module code:
Option Strict On
Module functionmodule
Public Function IsTelephoneNumberValid(number As String) As Boolean
Const NRegEx As String = "^[2-9]\d{2}$"
Const XXXXRegEx As String = "^\d{4}$"
Dim strippedNumber As String
Dim NPA As String
Dim NXX As String
Dim XXXX As String
strippedNumber = Replace(number, "[^0-9]", String.Empty)
If strippedNumber.Length = 11 AndAlso strippedNumber.Substring(0, 1) = "1" Then
strippedNumber = strippedNumber.Substring(1, 10)
ElseIf strippedNumber.Length <> 10 Then
Return False
End If
NPA = strippedNumber.Substring(0, 3)
NXX = strippedNumber.Substring(3, 3)
XXXX = strippedNumber.Substring(6, 4)
If Not IsMatch(NPA, NRegEx) OrElse Not IsMatch(NXX, NRegEx) _
OrElse Not IsMatch(XXXX, XXXXRegEx) Then
Return False
ElseIf NPA.Substring(0, 2) = "37" OrElse NPA.Substring(0, 2) = "96" Then
Return False
ElseIf NXX.Substring(1, 2) = "11" AndAlso (CInt(NXX) >= 211 AndAlso CInt(NXX) <= 911) Then
Return False
ElseIf NXX = "912" OrElse NXX = "913" OrElse NXX = "914" _
OrElse NXX = "915" OrElse NXX = "916" Then
Return False
ElseIf NXX = "700" OrElse NXX = "950" OrElse NXX = "958" OrElse NXX = "959" Then
Return False
ElseIf NXX = "555" Then
If CInt(XXXX) >= 100 AndAlso CInt(XXXX) <= 199 Then
Return False
End If
End If
Return True
End Function
Private Function IsMatch(xXXX As String, xXXXRegEx As String) As Boolean
Throw New NotImplementedException()
End Function
End Module