javascript - Verify date with regular expressions -
this question has answer here:
- how write regex validate dates? 6 answers
date format 2015/04/25 trying
^\d{4}\/\d{2}\/\d{2}$ and working fine, want validate month should b less 12 , date less 31
i had tried this
^\d{4}\/(\d{2}\<[12])\/\d{2}$ but not working.
ps: noob in regular expressions.
you can use
^\d{4}\/(0\d|1[0-2])\/([0-2]\d|3[01])$ explanation:
\d{4}4 digits(0\d|1[0-2])0(any digit) or 1(0 2) i.e00 09or10-12([0-2]\d|3[01])(0 2)(any digit) or 3(0 or 1) i.e00 29or30 or 31
edit1: if want match 01-12 months , 01-31 day (without 00) can use :
^\d{4}\/(0[1-9]|1[0-2])\/(0[1-9]|[12]\d|3[01])$ edit2: if want strict validation of dates use explode , checkdate.. suggested @wayne.. since includes validation of leap years.
see demo
Comments
Post a Comment