JqGrid date format judgment sample code of start date and end date
- 2020-03-26 23:49:15
- OfStack
var beginValue = " The start time ";
var endValue = " The end of time ";
var dispaly = jQuery("#testSubjectGrid").jqGrid("getCell", idArray[i], "display_content");
if (CheckDate(begindata, dispaly, beginValue) == false) {
return false;
}
if (CheckDate(enddata, dispaly, endValue) == false) {
return false;
}
//Verification of date (yyyy-mm-dd)
function CheckDate(strDate, i, dataValue) {
var reg = /^(/d{4})([-])(/d{2})([-])(/d{2})/;
if (!reg.test(strDate)) {
jAlert(" The first " + i + " line "+dataValue+" Incorrect date format !/n The correct format is :2007-01-01", " Prompt information ");
return false;
}
var ss = strDate.split("-");
var year = ss[0];
var month = ss[1];
var date = ss[2];
if (!checkYear(year, i)) {
return false;
}
if (!checkMonth(month, i,dataValue)) {
return false;
}
if (!checkDate(year, month, date, i,dataValue)) {
return false;
}
return true;
}
//Year judgment
function checkYear(year, i,dataValue) {
if (isNaN(parseInt(year))) {
jAlert(" The first " + i + " line "+dataValue+" Is incorrectly entered , Please re-enter !", " Prompt information ");
return false;
}
else if (parseInt(year) < 1900 || parseInt(year) > 2100) {
jAlert(" The first " + i + " line " + dataValue + " Should be in 1900-2100 between !", " Prompt information ");
return false;
}
else {
return true;
}
}
//In judging
function checkMonth(month, i, dataValue) {
if (isNaN(parseInt(month))) {
jAlert(" The first " + i + " line "+dataValue+" Is not entered correctly , Please re-enter !", " Prompt information ");
return false;
}
if (month.substring(0, 1) == 0) {
if (parseInt(month.substring(1, 2)) < 1) {
jAlert(" The first " + i + " line "+dataValue+" Should be in 1-12 between !", " Prompt information ");
return false;
}
}
else if (parseInt(month) < 1 || parseInt(month) > 12) {
jAlert(" The first " + i + " line "+dataValue+" Should be in 1-12 between !", " Prompt information ");
return false;
} else {
return true;
}
}
//Date of judgment
function checkDate(year, month, date, i,dataValue) {
var daysOfMonth = CalDays(parseInt(year), parseInt(month));
if (isNaN(parseInt(date))) {
jAlert(" The first " + i + " line "+dataValue+" The date of , Please re-enter !", " Prompt information ");
return false;
}
else if (parseInt(date) < 0 || parseInt(date) > daysOfMonth) {
jAlert(" The first " + i + " line "+dataValue+" The date should be in 1-" + daysOfMonth + " between !", " Prompt information ");
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;
}
}