Sample Code for jqGrid Date Format determination (start date and end date)

Source: Internet
Author: User
Tags jqgrid

Copy codeThe Code is 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;
}

 

// Verify the date (yyyy-mm-dd)
Function CheckDate (strDate, I, dataValue ){
Var reg =/^ (/d {4}) ([-]) (/d {2}) ([-]) (/d {2 })/;
If (! Reg. test (strDate )){
JAlert ("the" + I + "row" + dataValue + "date format is incorrect! /N 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 determination
Function checkYear (year, I, dataValue ){
If (isNaN (parseInt (year ))){
The year of jAlert ("+ I +" row "+ dataValue +" is incorrect. Please enter it again! "," Prompt information ");
Return false;
}
Else if (parseInt (year) <1900 | parseInt (year)> 2100 ){
JAlert (the year of "+ I +" row "+ dataValue +" should be! "," Prompt information ");
Return false;
}
Else {
Return true;
}
}
// Month judgment
Function checkMonth (month, I, dataValue ){
If (isNaN (parseInt (month ))){
JAlert ("+ I +" row "+ dataValue +" Incorrect month input. Please enter it again! "," Prompt information ");
Return false;
}
If (month. substring (0, 1) = 0 ){
If (parseInt (month. substring (1, 2) <1 ){
JAlert (the month of "+ I +" row "+ dataValue +" should be between 1 and 12! "," Prompt information ");
Return false;
}
}
Else if (parseInt (month) <1 | parseInt (month)> 12 ){
JAlert (the month of "+ I +" row "+ dataValue +" should be between 1 and 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 ("+ I +" row "+ dataValue +" Date input is incorrect. Please enter it again! "," Prompt information ");
Return false;
}
Else if (parseInt (date) <0 | parseInt (date)> daysOfMonth ){
JAlert ("the" + I + "row" + dataValue + "date should be between 1-" + daysOfMonth +! "," 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 & amp; year % 100! = 0) | (year % 400 = 0 )){
Return true;
} Else {
Return false;
}
}

Related Article

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.