Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phone Number Validation Javascript

I want users to allow only phone numbers in following format

xxx-xxx-xxxx or xxxxxxxxxx all digits only . Can some one suggest a regular expression to do this ?

like image 911
Pit Digger Avatar asked Jun 01 '11 01:06

Pit Digger


People also ask

How can I validate a phone number in JavaScript?

Validate a Phone Number Using a JavaScript Regex and HTML function validatePhoneNumber(input_str) { var re = /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/; return re. test(input_str); } function validateForm(event) { var phone = document. getElementById('myform_phone').

How do I validate a mobile number?

Mobile Number validation criteria:The first digit should contain numbers between 6 to 9. The rest 9 digit can contain any number between 0 to 9. The mobile number can have 11 digits also by including 0 at the starting. The mobile number can be of 12 digits also by including 91 at the starting.

How do I validate a 10 digit mobile number?

you can also use jquery for this length==10){ var validate = true; } else { alert('Please put 10 digit mobile number'); var validate = false; } } else { alert('Not a valid number'); var validate = false; } if(validate){ //number is equal to 10 digit or number is not string enter code here... } Save this answer.


1 Answers

Something like this:

\d{3}-\d{3}-\d{4}|\d{10}
like image 135
Alex Aza Avatar answered Sep 23 '22 01:09

Alex Aza