Home >Web Front-end >JS Tutorial >jquery validator plug-in adds date comparison method_jquery

jquery validator plug-in adds date comparison method_jquery

WBOY
WBOYOriginal
2016-05-16 18:34:13940browse

Official address: http://bassistance.de/jquery-plugins/jquery-plugin-validation/
Script Homehttp://www.jb51.net/jiaoben/17478. html
Due to the needs of the project, it is essential that the date size is relatively large, but the Validation plug-in does not have this function. At this time, we need to extend a custom verification method. The code is as follows:

Copy code The code is as follows:

$(document).ready(function() {
$("#<%= btnSubmit.ClientID %>").click(function() {
$("#aspnetForm").validate({
rules: {
ctl00$ ContentPlaceHolder1$ucProjInfo1$ucDatePicker2$txtDatePicker: {
required: true,
date: true,
//Date comparison verification method
endDate: true
}
}
} );
});
//Custom validation method
jQuery.validator.addMethod("endDate",
function(value, element) {
var startDate = $('# start_date').val();
return new Date(Date.parse(startDate.replace("-", "/"))) <= new Date(Date.parse(value.replace("-" , "/")));
},
"The end date must be greater than the start date!");
});
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn