Introduction
In this article, we shall learn how to do client-side validation of the U.S. format phone numbers using three textbox fields. It means the application will be more responsive because the load on the server is reduced. JavaScript uses the client machine processing power.
You can find many solutions on the web but I found that most of these solutions are to validate the phone number from one text box. Here, I’m getting input in three text fields.
The following image shows phone number input fields (eg: 111 222 3333)

Method 2 Validation Conditions
Each textbox field should pass the following validation.
- The first two fields must consist of the length of three digits and the third field must consist of the length of four digits.
- All three fields must have numeric values.
- If the user has entered value in one field, other fields shouldn’t be empty.
Before we start, just note
Eg: document.form1.area (is just an object), document.form1.area.value (has a value of that area object)
Method 1 - (Phone Number is a mandatory field)
To validate this condition is very simple.div>
- If(!document.form1.area || !document.form1.Prefix || !document.form1.Suffix) {
- Alert(“Phone Number shouldn’ t be empty”);
- document.form1.area.focus();
- return false;
- } div>
Method 2 (Phone Number not mandatory but validate if the user has entered value at one textbox field)
If the user does not enter any value.
- If(!document.form1.area || !document.form1.Prefix || !document.form1.Suffix)
- Return true; // return true. Because ph.no is not mandatory here. div>
If the user has entered a value in any of the textboxes, then the validation should pass the above three conditions.
Condition 1 - Validate Field length’s
The first two fields (AreaCode and Prefix) should consist of 3 digits.
- If(document.form.area1.value.length != 3) {
- Alert(“Area code must have 3 digits”);
- Document.form.area1.focus();
- Return false
- } div>

Nandhini SPosted Aug 21, 2017, 10:40 PM
Nice Article....... Thanks for sharing.....