0

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

hello ,

i would like to know what is the meaning behind in these ^ ,[- ],$ symbols???

and i would able to follow that the script logically verifying the format of text being entered!!

i.e NNN-NN-NNNN...

Thanks in Advance ..

Srini.

2
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by srinidelite
1

You're looking at a regular expression. The pattern that is defined in this expression happens as follows:

  • / opens the regular expression
  • ^ specifies that the match must be at the start of the string being queried
  • [0-9] match any numeric character
  • {3} the previous statement should be matched exactly three times
  • [- ] match the hyphen or space character
  • ? there should be either zero or one of the preceeding match
  • [0-9] match any numeric character
  • {2} the previous statement should be matched exactly two times
  • [- ] match the hyphen or space character
  • ? there should be either zero or one of the preceeding match
  • [0-9] match any numeric character
  • {4} the previous statement should be matched exactly four times
  • $ specifies that the string is only a match if it has now reached the end of the string

This expression when run will match the following strings, where n is any digit:

  • nnn-nn-nnnn
  • nnn-nn nnnn
  • nnn nn-nnnn
  • nnn nn nnnn
  • nnnnn nnnn
  • nnnnn-nnnn
  • nnn-nnnnnn
  • nnn nnnnnn
  • nnnnnnnnn

It will not, however, match strings like the following:

  • nnn*nn*nnn
  • nn-nnn-nnnn

Does that make sense?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.