any of the more common questions asked of the VB Pro involve formatting and validating data.In this 10-Minute Solution, you'll learn how to validate and format a phone number.While we won't deal with international (non-US) phone numbers here, you can apply these techniques to your local phone number format.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.Numbers entered without area codes will have a default area code prepended to them. Any extensions will be listed as xnnnnn following the phone number. If an initial 1 is added to the number, it will be removed, since users already know to dial a one before making a long distance call.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.
If you're going to be using the application in different locations, you may want to store that information with the application user's profile, similar to the way that Windows stores your favorite locations for dialing.
He is certified in Visual Basic 5.0 and Windows Architecture (1 and 2).
Question: How to validate number values to and block all letters and symbol in a form.
The computer is now smart enough to automatically translate data into the format that has been pre-selected for use in that system, saving timeand no doubtmoney.
Eric Smith has been a senior consultant with Andersen Consulting, specializing in client/server development using Oracle and Visual Basic, and was senior content developer (Visual Basic) at before it was purchased by Fawcette Technical Publications.