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); 
3
  • 1
    what do you want in your validation Commented Dec 19, 2016 at 6:35
  • For Indian numbers: /[7-9][0-9]{9}/. Note this is a basic validation regex. This will not cover cases like 9999999999 Commented Dec 19, 2016 at 6:36
  • Possible duplicate of HTML5 phone number validation with pattern Commented Dec 19, 2016 at 6:38

1 Answer 1

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; } } 
Sign up to request clarification or add additional context in comments.

1 Comment

Note, its better to use regex.test

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.