Kalima adult webcam - Validating telephone numbers

All numbers will at least be in the format (nnn) nnn-nnnn.

validating telephone numbers-44

Arizona dating personals no registration - Validating telephone numbers

This blog post focuses on validating the last of those : Social Security Numbers and why they may be a bit deceivingly more difficult to validate than you might expect.

I’ll provide a few different methods to handle the actual validation through Regular Expressions and let you determine which one might best suit your needs.

0)\d # Don't allow last four digits to be "0000" $ # End of expression This is an expression that I wrote that would slightly elaborate a bit more on the previous example and would handle some commonly encountered “fake” values or ones that might easily be forged in an area that might require a user to enter to enter one.

Let’s break this one down : ^ # Start of expression (?!

In the United States, there are a number of valid formats for phone numbers that might be entered into a form: There are many other variations of this, as well, but those examples should be enough to give you an idea of what we're dealing with here.

Because there are so many valid formats, you're going to have to set some rules for reformatting these phone numbers: 1.

With these rules in mind, let's create the validation code for a text box named txt Phone: Private Sub txt Phone_Validate(Cancel As Boolean) Dim str Temp As String Dim str Phone As String Dim str Extension As String Dim int Result As Integer Const Default Area Code = "703" ' ' Remove all the grouping characters for ' now. ' str Temp = Replace(txt Phone, "(", "") str Temp = Replace(str Temp, ")", "") str Temp = Replace(str Temp, "-", "") str Temp = Replace(str Temp, " ", "") str Temp = Replace(str Temp, "X", "x") ' ' Break up the digits into the number and ' the extension, if any.

' int Result = In Str(1, str Temp, "x", vb Text Compare) If int Result 0 Then str Extension = Mid(str Temp, int Result 1) str Phone = Left(str Temp, int Result - 1) Else str Phone = str Temp End If If Left(str Phone, 1) = "1" Then str Phone = Mid(str Phone, 2) End If If Len(str Phone) 10 Then Msg Box "Please enter a valid telephone number.", vb Exclamation Cancel = True Exit Sub End If ' ' Prepend the default area code ' If Len(str Phone) = 7 Then str Phone = Default Area Code & str Phone End If ' ' Build the new phone number ' txt Phone = "(" & Left(str Phone, 3) & ") " _ & Mid(str Phone, 4, 3) & "-" _ & Right(str Phone, 4) ' ' Add the extension, if any ' If str Extension I used a default area code of 703, which you can obviously change as needed.

Use your best judgement to determine if this is a viable option for you and your business needs.

Tags: , ,