javascript - How do I use a regular expression to match a fixed-length number with a hyphen in the middle? -


i new regular expressions , wanted know how write regular expression following:

validates string 123-0123456789. numeric values , hyphen should allowed. also, verify there 3 numeric chars before hyphen , 10 chars after hyphen.

the given answers won't work strings more digits (like '012-0123456789876'), need:

str.match(/^\d{3}-\d{10}$/) != null; 

or

/^\d{3}-\d{10}$/.test(str); 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -