I made a date format with jQuery Validator, in this format: dd/mm/yyyy.
But I'm having a problem with this format in Google Chrome. In IE or Firefox, the date format is working well, but in Google Chrome, the format accept in maximum 12/12/yyyy. For example, the date 20/12/2014 in IE is ok, but in Chrome, the date is not accept.
The code:
$.validator.addMethod(
"brDate",
function(value, element) {
return value.match(/^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/);
},
"The correct date format is dd/mm/yyyy."
);
Most of the validators already have date validation methods.
Which one are you using?
http://**formvalidator.net**/#default-validators_dates
<!-- Validate date formatted yyyy-mm-dd -->
<input type="text" data-validation="date">
<!-- Validate date formatted dd/mm/yyyy -->
<input type="text" data-validation="date" data-validation-format="dd/mm/yyyy">
I'd suggest to use such validation.
If you want to write pattern you self, you can use this one:
^(((0?[1-9]|1[012])/(0?[1-9]|1\d|2[0-8])|(0?[13456789]|1[012])/(29|30)|(0?[13578]|1[02])/31)/(19|[2-9]\d)\d{2}|0?2/29/((19|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(([2468][048]|[3579][26])00)))$
MM/dd/yyyy with 100% leap years. Valid since year 1900. MM and DD could have 1 or 2 digits : M/d/yyyy or MM/d/yyyy or M/dd/yyyy
Taken from http://regexlib.com/REDetails.aspx?regexp_id=1071
finally I solved the problem.
jQuery.validator.methods["date"] = function (value, element) { return true; }
font: Unobtrusive validation in Chrome won't validate with dd/mm/yyyy
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With