I am trying to use a javascript regular expression to validate date of birth textbox. here is my code
var patt=/[0-9]{1,2}/[0-9]{1,2}/[0-9]{4}/;
alert(patt.test("1985/08/03"));
and the error said: SyntaxEror: Unexpected token {
I don’t understand why, this pattern works fine in the asp.net RegularExpressionValidator controller.
Many thanks
You need to escape the
/characters, otherwise the interpreter sees the first one and thinks that’s the end of the regexp.You should also put anchors in your regexp to ensure it matches the whole string, and doesn’t match any string which happens to contain that pattern.
For brevity you can use
\dinstead of[0-9], too:NB: your sample doesn’t work – you’ve put the year first, but the RE is expecting it to be last.