Jqgrid Date format Judgment sample code (start date and end date) _jquery

Source: Internet
Author: User
Tags jqgrid

Copy Code code as follows:

var beginvalue = "Start Time";
var endvalue = "End 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;
}

Validation of dates (YYYY-MM-DD)
function Checkdate (strdate, I, DataValue) {
var reg =/^ (/d{4}) ([-]) (/d{2}) ([-]) (/d{2})/;
if (!reg.test (strdate)) {
Jalert ("First" + i + "line" +datavalue+ "date format is incorrect!/n correct format: 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+ "the year entered incorrectly, please re-enter!", "prompt Information");
return false;
}
else if (parseint) < 1900 | | parseint (YEAR) > 2100) {
Jalert ("First" + i + "line" + DataValue + "Year should be between 1900-2100!", "hint info");
return false;
}
else {
return true;
}
}
Month Judgment
function checkmonth (month, I, DataValue) {
if (isNaN (parseint (month)) {
Jalert ("the" "+ i +" line "+datavalue+" the month input is incorrect, please re-enter! "," prompt Information ");
return false;
}
if (month.substring (0, 1) = = 0) {
if (parseint (month.substring (1, 2)) < 1) {
The month of Jalert ("the first" + i + "line" +datavalue+ "should be between 1-12!", "prompt Information");
return false;
}
}
else if (parseint (month) < 1 | | | parseint (MONTH) > 12) {
The month of Jalert ("the first" + i + "line" +datavalue+ "should be between 1-12!", "prompt Information");
return false;
} else {
return true;
}
}
Date Judgment
function checkdate (year, month, date, I,datavalue) {
var daysofmonth = caldays (parseint (year), parseint (month));
if (isNaN (parseint (date)) {
Jalert ("the" "+ i +" line "+datavalue+" date entered incorrectly, please re-enter! "," prompt Information ");
return false;
}
else if (parseint (date) < 0 | | parseint (DATE) > Daysofmonth) {
Jalert ("First" + i + "line" +datavalue+ "date should be in 1-" + Daysofmonth + "between!", "hint info");
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;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.