- <html>
- <head>
- <title>测试八位数字是否为有效日期</title>
- </head>
- <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>
- <body>
- <div>
- <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();"/>
- </div>
- </body>
- </html>
新闻热点
疑难解答