问题
I have rendered the normal text with jquery date rule. The date rule working fine in chrome but not working in the Firefox and IE . please see my code block.
<form id="myform">
<input id="datepick" type="text" name ="datepick"/>
<input type="submit" id="ValidateDate" />
</form>
$("#myform").validate({
rules: {
datepick:{
date:"MM/dd/yyyy"
}
},
messages: {
datepick:{
date:"Give MM/dd/yyyy format"
}
}
});
$('#datepick').keyup(function () {
$("#ValidateDate").submit();
});
</script>
when i type 12/3err/3001 it throws error in all browser
when i type 12/234/2333 it throws error chrome not in firefox and IE.
Additionally i want to share one information.
http://jqueryvalidation.org/date-method/
In the above link jQuery validation is not working properly in Mozilla , IE browser even for a normal textbox.
please type the 22/233/2222 value in the above jquery link sample then you can find the below output variation
In chrome :
In Firefox:
Please help me to resolve this.....
Thanks,
Gobalakrishnan
回答1:
The documentation you've linked to says this:
This method should not be used, since it relies on the new Date constructor, which behaves very differently across browsers and locales. Use
dateISOinstead or one of the locale specific methods (in localizations/ and additional-methods.js).
My emphasis.
回答2:
This issue is due to the date parsing behavior difference between the browsers. You can see the below.
Chrome
new Date("92/12/2015") - Invalid Date
FireFox
new Date("92/12/2015") - Date {Sun Jun 07 1998 00:00:00 GMT+0530 (India Standard Time)}
The date rule will only check for format based on inputted date value and hence the validation succeeded in FF.
So as @SomekidwithHTML proposed you can use the dateIso which will check the date against ISO date standards or implement your our custom validation as per your need.
http://jqueryvalidation.org/jQuery.validator.addMethod/
来源:https://stackoverflow.com/questions/34367315/jquery-date-rule-not-working-in-firefox-and-ie