0

I want to check if the input matches this format:

format: "dd/MM/yyyy"

Of course they would have to me numbers. What is the regex expression, and/or jquery/javascript function that i'd use to make sure this input matches this?

3
  • Do you want to ensure it's in that format and/or a valid date? Commented Jan 18, 2012 at 20:34
  • No suggestions yet, so nothing. Commented Jan 18, 2012 at 20:34
  • valid date would be much better. Commented Jan 18, 2012 at 20:34

3 Answers 3

1

Try this:

var matches = str.search(/^\d{2}\/\d{2}\/\d{4}$/) > -1;
Sign up to request clarification or add additional context in comments.

Comments

1

This should do it:

/^[0123]?\d\/[01]?\d\/\d{2,}$/

Remember that only certain numbers are valid months and days.

Other approaches can be found at the Regular Expression Library.

Comments

0

If you just wanted to check the format, and not if it's actually a valid date, the following should work:

/\d{2}\/\d{2}\/\d{4}/

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.