YYYY-MM-DD format
The following are:
| The code is as follows |
Copy Code |
| /^d{4}-d{1,2}-d{1,2}$/ |
4 digits, horizontal lines, 1 or 2 digits, a horizontal line, and finally 1 or 2 digits.
The test code is as follows:
| code is as follows |
copy code |
|
< Script type= "Text/javascript" >
function testreg (reg,str) {
return reg.test (str);
}
var reg =/^d{4}-d{1,2}-d{1,2}$/;
var str = ' 2008-8-8 ';
var str2 = ' 2008-08-08 ';
var str3 = ' 08-08-2008 ';
var str4 = ' 2008 08 08 ';
document.write (Testreg (reg,str) + ' <br/> ');
document.write (Testreg (REG,STR2) + ' <br/> ');
document.write (Testreg (REG,STR3) + ' <br/> ');
document.write (Testreg (REG,STR4) + ' <br/> ');
</script> |
Second Kind
| The code is as follows |
Copy Code |
|
Yyyy-mm-dd
Or
Yyyy/mm/dd |
Just use the "or" to simply change the line.
| The code is as follows |
Copy Code |
|
/^D{4} (-|/) d{1,2} (-|/) d{1,2}$/ |