Example
var a=/^[1-2]d{3}-(0?[ 1-9]|1[0-2])-(0?[ 1-9]| [12] [0-9]|3[0-1]) $/;
if (!) 2006-6-6 ". Match (a)) {
Alert ("date format is not correct!")
}
See a date validation function
<script language= "Web Effects" >
function Check () {
var a=/^[1-2]d{3}-(0?[ 1-9]|1[0-2])-(0?[ 1-9]| [12] [0-9]|3[0-1]) $/;
if (Document.biao.riqi.value.match (a)) {
Alert ("date format is not correct!")
return False
}
Else
return True
}
</script>
And look at a super beautiful date validation function
function IsDate (b) {
var birth = b.split ('-');
var bir = birth[1]+ '/' +birth[2]+ '/' +birth[0];
var d = new Date (BIR);
var dd = D.format (' mm/dd/yyyy ');
var df = dd.split ('/');
if (df[2]!=birth[0]| | df[0]!=birth[1]| | Df[1]!=birth[2]) {
return false;
}
return true;
}
function Isdates (b) {
var a =/^d{4}[-]d{2}[-]d{2}$/;
if (!a.test (b)) {
return false;
}
return true;
}
Let's look at a date validation instance code
<title>javascript Check to see if the date format is correct </title>
<script language= "JavaScript" >
function Check () {
str = form1.txt.value;
str = str.match (/^ (d{2,4}) (-|/) (d{1,2}) (d{1,2}) $/);
if (str = null) {
Alert (' You enter an invalid date format ');
return false;
}else if (str[3]>12 | | str[4]>31) {
Alert ("The date format you entered is invalid");
return false
}else{
Alert ("The date format you entered is valid");
return true;
}
</script> <body>
<form name= "Form1" onsubmit= "return check ( >
<input type= "text" name= "TXT" >
<input type= "Submit" value= "verify" >
</form>
</ Body>