Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i need validation for phone number to accept only 12 digits and it should accept spaces and phonenumber should not start with digit 1


here is the validation i tried but here its not at all accepting 1 digit .in my case 1 should not start from first that's it.how to do?


var phonepat=/^[\s()+-]*([02-9][\s()+-]*){7,12}$/;
Posted

Try:
^[023456789](\d|\s){11}$

If you are going to be playing with regular expressions, get a copy of Expresso [^] - it's free, and it examines and generates Regular expressions.
 
Share this answer
 
Comments
deepa ashwi 24-Nov-13 10:46am    
ok griff thank you
Twelve digits? That's a lot. We only use ten in the U.S.; where are you?


Here's an expression that works pretty well for U.S. phone numbers ^((?'Paren'\()?[02-9]\d{2}(?(Paren)\)))?[-\s]*\d{3}[-\s]*\d{4}$

Bear in mind that Expresso and my RegexTester[^] use .net's implementation of Regular Expressions and may have features that Javascript doesn't.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900