检测八位数字是否为有效日期的正则

时间:2021-11-29 01:21:08
  1. <html> 
  2. <head> 
  3. <title>测试八位数字是否为有效日期</title> 
  4. </head> 
  5. <script language="javascript"><!--     /*         // Regex Example in JavaScript         // Rainsome Studio                 // 2009-07-16 in Shanghai         //测试八位数字是否为有效日期     */         function fun1()     {         var str1=document.getElementById("str1").value;         var str2=document.getElementById("str2").value;             var regex1 = new RegExp(str2,'g');         return regex1.test(str1);         }     function fun2(){alert(fun1());}      // --></script> 
  6. <body> 
  7. <div> 
  8.     <span>String : </span><input id="str1" type="text" value="19990228" size="100"/><span>Regex : </span><input id="str2" type="text" value='^(?:(?:(?:(?=\d{2}(?:(?:[02468][048])|(?:[13579][26])))\d{4}02(?!00)[0-2]\d))|(?:\d{4}(?:(?:(?:(?:0[469])|(?:11))(?!00)(?:(?:[0-2]\d)|(?:30)))|(?:(?:(?:0[13578])|(?:1[02]))(?!00)(?:(?:[0-2]\d)|(?:3[01])))|(?:02(?!(?:00)|(?:29))[0-2]\d))))$' size="100"/><input type="button" value="OK" onclick="javascript:fun2();"/> 
  9. </div> 
  10. </body> 
  11. </html>