Jquery validate date comparison custom Verification Method

Source: Internet
Author: User
Tags date1
<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en" >
< Html >
  < Head >
< Title > New Document </ Title >
< Meta Name = "Generator" Content = "Editplus" >
< Meta Name = "Author" Content = "" >
< Meta Name = "Keywords" Content = "" >
< Meta Name = "Description" Content = "" >
< Script Type = "Text/JavaScript" SRC = "Jquery-1.4.2.js" > </ Script >
< Script Type = "Text/JavaScript" SRC = "Jquery. Validate. js" > </ Script >
< Script Language = "JavaScript" >
<! --
Jquery ( Function (){
Jquery. validator. Methods. comparedate =   Function (Value, element, Param ){
// VaR startdate = jquery (PARAM). Val () + ": 00"; supplemented in yyyy-mm-dd hh: mm: SS format
// Value = value + ": 00 ";

VaR Startdate = Jquery (PARAM). Val ();

VaR Date1 =   New Date (date. parse (startdate. Replace ( " - " , " / " )));
VaR Date2 =   New Date (date. parse (value. Replace ( " - " , " / " )));
Return Date1 < Date2;
};

Jquery ( " # Form1 " ). Validate ({
Focusinvalid: False ,
Rules :{
" Timestart " :{
Required: True
},
" Timeend " :{
Required: True ,
Comparedate: " # Timestart "
}
},
Messages :{
" Timestart " :{
Required: " Start time cannot be blank "
},
" Timeend " :{
Required: " End Time cannot be blank " ,
Comparedate: " The end date must be later than the start date! "
}
}
});
});
// -->
</ Script >
  </ Head >

< Body >
  < Form ID = "Form1" Name = "Form1" Method = "Post" Action = "Demo.html" >
< P > Timestart:
< Input Name = "Timestart" Type = "Text" ID = "Timestart" Value = "10:00:00" > Yyyy-mm-dd hh: mm: SS
</ P >
< P > Timeend:
< Input Name = "Timeend" Type = "Text" ID = "Timeend" Value = "9:00:00" > Yyyy-mm-dd hh: mm: SS
</ P >
< P >
< Input Type = "Submit" Name = "Submit" Value = "Submit" >
</ P >
  </ Form >

  </ Body >
</ Html >

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.