Example 1
| The code is as follows |
Copy Code |
|
/**
Determine the date format entered in the input box is YYYY-MM-DD and the correct date
*/
function IsDate (sm,mystring) {
var reg =/^ (d{4})-(D{2})-(d{2}) $/;
var str = mystring;
var arr = reg.exec (str);
if (str== "") return true;
if (!reg.test (str) &®exp.$2<=12&®exp.$3<=31) {
Alert ("Please ensure that the date format entered in +sm+ is YYYY-MM-DD or the correct date!");
return false;
}
return true;
} |
Example 2
| The code is as follows |
Copy Code |
|
/**
Determine the date format entered in the input box is YYYY/MM/DD and the correct date
*/
Date format
[' Date_au ', function (v) {
if (vanadium.validators_types[' empty '].test (v)) return true;
var regex =/^ (d{2})/(D{2})/(d{4}) $/;
if (!regex.test (v)) return false;
var d = new Date (V.replace (Regex, ' $2/$1/$3 '));
Return (parseint (regexp.$2) = = (1 + d.getmonth ()) && (parseint (regexp.$1, 10) = =
D.getdate ()) && (parseint (regexp.$3,) = = D.getfullyear ());
}, |
Example 3
Here we have a more complete date format function
| The code is as follows |
Copy Code |
Whether it is a date format
function Checkdate (strdate) {
var reg =/^ (d{4})-(D{2})-(d{2}) $/;
if (!reg.test (strdate)) {
Alert ("date format is incorrect!/n the correct format is: 2004-01-01");
return false;
}
var year = strdate.substring (0, 4);
var month = strdate.substring (5, 7);
var date = strdate.substring (8, 10);
if (!checkyear (year)) {return false;}
if (!checkmonth (month)) {return false;}
if (!checkdate, month, date)) {return false;}
return true;
}
function Checkyear (year) {
if (isNaN (parseint (year)) {
Alert ("The year entered incorrectly, please re-enter!");
return false;
}
else if (parseint) < 1950 | | parseint (YEAR) > 2050) {
Alert ("Year should be between 1950-2050!");
return false;
}
else return true;
}
function Checkmonth (month) {
if (parseint (month)) {alert ("The month entered incorrectly, please re-enter!");
else if (parseint (month) < 1 | | | parseint (month, ten) > 12) {
Alert ("Month should be between 1-12");
return false;
}
else return true;
}
function checkdate (year, month, date) {
var daysofmonth = caldays (parseint (year), parseint (month));
if (isNaN (parseint (date)) {alert ("Enter the date incorrectly, please re-enter!");
else if (parseint (date) < 1 | | parseint (DATE) > Daysofmonth) {alert ("date should be between 1-" + Daysofmonth + "); return false; }
else return true;
}
Function caldays (year, month) {
var date = new Date (year, month, 0);
return Date.getdate ();
}
function Isleapyear (year) {
if (year% 4 = 0 && Year% 100!= 0) | | (Year% 400 = 0)) return true;
else return false;
} |