In this article we will discuss about regular expression for validating Phone number in various format.
In the following example user enters a phone number.
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums Hi I need to validate my mobile number it wants to be in 91-1234567890 this format If i enter 1234567890 its wants to show alert message your mobile wants to be in 91-1234567890 format If i enter 9112345678901 its wants to show alert message your mobile wants to be in 91-1234567890 format If i enter 9112345678901 its wants to show alert message your mobile wants to be in 91-1234567890 format and then the correct mobile format 91-1234567890 wants to save in My sql database. If the application is india based then you can proceed with 91 as country code or keep an array of all country codes and change the validation accordingly.
All i can say is investigate regular expressions this is a very simple one Hi Arun Please check this code. Also make use of component level of validation to restrict the user to enter only numerics and characters " " and "-" 2.
At last we check the length of the string and permit only phone numbers with 10 digits. When the user clicks the Submit button on the form, the form data is sent to a Java Script validation function that checks each field to make sure that it is in the appropriate format.Form data that typically are checked by a Java Script could be: validate Form On Submit ( ) This is a main function that calls a series of subfunctions, each of which checks a single form element for compliance.If the element complies than sufunction returns an empty string.validate Username ( ) The function below checks if the user entered anything at all in the username field.If its not blank, we check the length of the string and permit only usernames that are between 5 and 15 characters.