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.

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?

@DavidAntaramian .... Thanks for Reply .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.