简体   繁体   中英

regular expression for date validation in javascript

I have the following regular expression to validate the date in 'mm/dd/yyyy' format. It works for '12/11/2006'. But if I use '2/3/2011', it doesn't work. Could you please correct the following expression to accept '12/11/2006' or '2/3/2011' format? Thank you for help.

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

只需使0可选: 0?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM