简体   繁体   English

以mm / dd / yyyy格式表示的正则表达式

[英]Regular Expression in mm/dd/yyyy format

Below is the regular expression for mm/dd/yyyy format. 以下是mm/dd/yyyy格式的正则表达式。 BUT the expression is giving true for mmddyyyy format also. 但是该表达式对于mmddyyyy格式也适用。 It should return false without '/' . 它应该返回false而不带'/'

Anyone can change it to the required regex? 任何人都可以将其更改为所需的正则表达式吗?

/^(((0[13-9]|1[012])[-/]?(0[1-9]|[12][0-9]|30)|(0[13578]|1[02])[-/]?31|02[-/]?(0[1-9]|
1[0-9]|2[0-8]))[-/]?[0-9]{4}|02[-/]?29[-/]?([0-9]{2}(([2468][048]|[02468][48])|[13579][26])|
([13579][26]|[02468][048]|0[0-9]|1[0-6])00))$/

This is the regex you want 这是你想要的正则表达式

/^(((0[13-9]|1[012])[-/](0[1-9]|[12][0-9]|30)|(0[13578]|1[02])[-/]31|02[-/](0[1-9]|1[0-9]|2[0-8]))[-/][0-9]{4}|02[-/]29[-/]([0-9]{2}(([2468][048]|[02468][48])|[13579][26])|([13579][26]|[02468][048]|0[0-9]|1[0-6])00))$/

[-/]? will check for 0 or 1 occurrence of '/' in your string. 将检查您的字符串中是否出现0或1个'/'。 [-/] will check exactly 1 occurrence instead. [-/]将改为恰好检查1次出现。

Try this RegEx, its working 试试这个RegEx,它的工作原理

 var date = "21062016";//"21/06/2016"; var rgexp = /(^(((0[1-9]|1[0-9]|2[0-8])[/](0[1-9]|1[012]))|((29|30|31)[/](0[13578]|1[02]))|((29|30)[/](0[4,6,9]|11)))[/](19|[2-9][0-9])\\d\\d$)|(^29[/]02[/](19|[2-9][0-9])(00|04|08|12|16|20|24|28|32|36|40|44|48|52|56|60|64|68|72|76|80|84|88|92|96)$)/; var validate = rgexp.test(date); alert(validate); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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