Suresh Behera

The Microsoft .Net Junkies

News

Blogroll

Reading

JavaScript regular expression to validate SSN.

Nice to Regular expression.

var RE_SSN = /^[0-9]{3}[\- ]?[0-9]{2}[\- ]?[0-9]{4}$/;

JavaScript Tutorial: Regular Expressions

Thanks,

Suresh

Posted: Oct 08 2008, 03:45 PM by Suresh Behera | with 1 comment(s)
Filed under: ,

Comments

Jon von Gillern said:

Assuming javascript regular expressions don't stray too far from the standard, you can shorten this a lot. Not that it matters a whole lot if this one works, but it's good knowledge to have

^\d{3}-?\d\d-?\d{4}$

\d is equivalent to [0-9]

And if you're matching a single character, you don't need to make it a character class ([-]? is equivalent to -?)

# October 9, 2008 9:25 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)