I have to do client side validation(using javascript/JQuery) for the input value which should have date in dd/mm/yyyy format. Please share regular expression if exist. It should validate the date is proper in all context.
Thanks in advance, Ratnesh
I have to do client side validation(using javascript/JQuery) for the input value which should have date in dd/mm/yyyy format. Please share regular expression if exist. It should validate the date is proper in all context.
Thanks in advance, Ratnesh
Use
^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$
I was looking for the same thing and got it from here
This expression validates days from 01 to 31, months from 01 to 12 but it accepts any number with 4 digts for year (including 0000). And it returns true for wrong dates like 31/02/2015.
Use a regex online validator like this one in order to check if it suits you.
http://www.regular-expressions.info/dates.html
http://blog.brijeshradhika.com/2010/10/jquery-validation-date-mmddyyyy-format.html
A lot of this in google. You should have tried to find it at least.
Regex will validate your format, but won't validate if date makes logic sense (leap years and stuff). That's said:
Javascript date regex DD/MM/YYYY javascript regexp, validating date problem
and numerous others...
As an alternative to regular expressions you may wish to take a look at datejs
Using parse exact http://code.google.com/p/datejs/wiki/APIDocumentation#parseExact
you can do things like:
var myDate = Date.parseExact("19/12/2004", "dd/mm/yyyy");
And will return null, if the date cannot be parsed.
n.b. I haven't tested the code above, but it should work ok.