Jquery modify to determine whether the start date is greater than the end date, and the input must be a number

Source: Internet
Author: User
Tags dateformat

$ ("# Ets_begindata"). datepicker ({
Dateformat: 'yy-mm-dd ',
Showon: 'click ',
Changemonth: True,
Changeyear: True,
Buttontext: "select ",
Onclose: function (){
$ (This). focusin ();
$ (This). focusout ();
}
});
$ ("# Ets_enddata"). datepicker ({
Dateformat: 'yy-mm-dd ',
Showon: 'click ',
Changemonth: True,
Changeyear: True,
Buttontext: "select ",
Onclose: function (){
$ (This). focusin ();
$ (This). focusout ();
}
});

// Save the modification.
Jquery. validator. addmethod ("checkdata", function (value, element ){
VaR begindate = $ ("# ets_begindata"). Val ();
VaR enddate = $ ("# ets_enddata"). Val ();
VaR dt1 = new date (begindate. Replace (/-/g, "/"); // convert to date type
VaR dt2 = new date (enddate. Replace (/-/g, "/"); // convert to date type
Return this. Optional (element) | dt1 <= dt2;
},"");
Jquery. validator. addmethod ("examvalidate", function (value, element ){
VaR length = value. length;
VaR examnumbids =/^ [-/+]? /D + (/./d + )? $ /;
Return this. Optional (element) | examnumbids. Test (value );
}, "The number of test sessions must be a number ");
$ ("# Entrancetestsubjectfrom"). Validate ({
Event: "Blur ",
Debug: True,
Ignore: ": hidden ",
Errorelement: "Div ",
Wrapper: "Div ",
Errorplacement: function (error, element ){
Error. addclass ('message ');
Error. appendto (element. Parent ());
},
Rules :{
"Ets_begindata ":{
Required: True,
Dateiso: True
},
"Ets_enddata ":{
Required: True,
Dateiso: True,
Checkdata: True
},
"Ets_examid ":{
Required: True,
Maxlength: 8,
Examvalidate: True
}
},
Messages :{
"Ets_begindata ":{
Required: "The start date cannot be blank! ",
Dateiso: "enter a valid date, for example, in the format of (2000-01-01 )"
},
"Ets_enddata ":{
Required: "the end date cannot be blank! ",
Dateiso: "enter a valid date, for example, in the format of (2000-01-01 )",
Checkdata: "the end date must be greater than or equal to the start date"
},
"Ets_examid ":{
Required: "The number of test sessions cannot be blank! ",
Maxlength: "The length of the test session cannot exceed 8 letters ",
Examvalidate: "The number of test sessions must be a number"
}
},
Submithandler: function (form ){
If ($ ("# entrancetestsubjectfrom"). Validate (). Form ())
$ ("# Entrancetestsubjectfrom"). ajaxsubmit ({
URL :"",
Datatype: 'json ',
Data :{
ID: IDS
},
Clearform: false,
Success: function (data ){
VaR JSON = eval ("(" + Data + ")");
Jalert (JSON. MSG, "prompt message ");
If (JSON. suc = 1 ){
$ ("# Grid"). Trigger ("reloadgrid ");
Reloadnum ++;
}
}
});
}
});

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.