0

How to add validation of mobile no. Html code:<input type="text" id="mob" name="mob[]" placeholder="Enter mobile no" required>

js code

container.appendChild(document.createTextNode("mobile"));
var input_m = document.createElement("input");
input_m.type = "text";
input_m.id= id+'_mobile';
input_m.name= "mob[]";
container.appendChild(input_m);
  • 1
    what do you want in your validation – Himanshu Tanwar Dec 19 '16 at 06:35
  • For Indian numbers: `/[7-9][0-9]{9}/`. Note this is a basic validation regex. This will not cover cases like `9999999999` – Rajesh Dec 19 '16 at 06:36
  • Possible duplicate of [HTML5 phone number validation with pattern](http://stackoverflow.com/questions/19611599/html5-phone-number-validation-with-pattern) – Manwal Dec 19 '16 at 06:38

1 Answers1

1

Well you can do this through regex:

function phonenumber(inputtxt)  {  
    var phoneno = /^\d{10}$/;  
    if((inputtxt.value.match(phoneno)) {  
        return true;  
    } else {  
        alert("message");  
        return false;  
    }  
}  
Andrew Li
  • 55,805
  • 14
  • 125
  • 143
Chetan Mehta
  • 349
  • 3
  • 12