Javascript function for validating phone number

Regular expressions are patterns used to match character combinations in strings.In Java Script, regular expressions are also objects.With all of this in mind, let’s look at the regular expression again after breaking it into its pieces. : # Group but don't capture: [0-9] # Match a digit. ITU-T Recommendation E.123 (“Notation for national and international telephone numbers, e-mail addresses and web addresses”) can be downloaded at Because this version is written using free-spacing style, the literal space character has been replaced with ^ # Assert position at the beginning of the string. ITU-T Recommendation E.164 (“The international public telecommunication numbering plan”) can be downloaded at RFC 5733 defines the syntax and semantics of EPP contact identifiers, including international phone numbers. Techniques used in the regular expressions in this recipe are discussed in Chapter 2. below is the code for validating mobile number with enter only numeric, length must be 10 digits and restrict user to entering illegal characters.There is two ways given below for validation of mobile numbers first normal way and another through regular expression.

This code validates a 10 digit phone number taken in any format and sets the phone number text field to the desired output format.

It gives an alert message if user enters data other than numbers. First argument is html / server control value, which is entered by user. There is one javascript function called "Validate No". Num Str : This is the value which you want to validate. It may by Text Box control (HTML or Server Control). String : This is predefined format which you can use to validate phone/fax number.

The first Text Box is Name that allows only characters and spaces.

This java Script code determine whether a user entered phone number in a common format that includes 0999999999, 099-999-999, (099)-999-9999, (099)9999999, 0, 099 999-9999, (099) 999-9999, 099.999.9999 and all related combinations For this we use this regular expression: /^\(?

Recently i have posted how to validate email address in javascript, how to validate mobile number and email address in jquery and not i will show you how to validate mobile number using simple javascript or using regular expression in javascript.

Leave a Reply