<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <SCRIPT LANGUAGE="JavaScript1.2"> var str="1 plus 2 equal 3"; var str2="11/23/55"; var results=str.match(new RegExp("\\d+","gi")); for(var i=0;i<results.length;i++){ document.write(results[i]+"<br/>"); } var res=str2.match(new RegExp("(\\d\\d?)/(\\d\\d?)/(\\d\\d)")); if(str2.length == res[0].length){ document.write(res[1]+"<br/>"); document.write(res[2]+"<br/>"); document.write(res[3]+"<br/>"); } </SCRIPT> </HEAD> <BODY> </BODY> </HTML> function dateCheck(value) { re = new RegExp("(\\d\\d?)/(\\d\\d?)/(\\d\\d)"); var result = value.match (re); if (result){ if (result[0].length != value.length){ alert ("Wrong date format. The correct format should be MM/dd/yy.") return false; }else{ var t = result[3]; var y = parseInt("20" + t); var m = parseInt(result[1], 10) - 1; var day = parseInt(result[2], 10); var d = new Date(y, m, day); if (d.getFullYear() != y || d.getMonth() != m || d.getDate() != day){ alert ("error date!") return false; }else{ var sm = result[1].length == 1?'0' + result[1]:result[1]; var sday = result[2].length == 1?'0' + result[2]: result[2]; var sy = result[3]; else return sm + 'https://www.jb51.net/' + sday + 'https://www.jb51.net/' + sy; } } }else{ alert ("Wrong date format. The correct format should be MM/dd/yy."); return false; } }
您可能感兴趣的文章: