0

I have a regular expression to validate the dates and it works fine, this is it

^(0[1-9]|[1-9]|1[012])[- /.](0[1-9]|[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$

But I want to validate it using the javascript. I tried with this

var  ck_effectivedate= /^(0[1-9]|[1-9]|1[012])[- /.](0[1-9]|[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$/;

function radtxtbxNewEffectiveDateOnBlur(sender, eventArgs) {

  if (!ck_effectivedate.test(sender.get_value())) {
    alert('matches');
   }
   else
   {
     alert('does not match');
   }

}

But, the regular expression is not working, because of the presence of / character in my regular expression which is also used to encapsulate the regular expression in java script.

If I remove the / character then it works, but I want to use that in my string. Please help.

1 Answer 1

3

You simply need to escape the special characters with a backslash \:

^(0[1-9]|[1-9]|1[012])[- \/.](0[1-9]|[1-9]|[12][0-9]|3[01])[- \/.](19|20)\d\d$

References:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.