Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome don't accept a specific date format using jQuery Validation

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."
    );
like image 343
marcelps Avatar asked Jun 30 '26 14:06

marcelps


2 Answers

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

like image 114
Denis Obydennykh Avatar answered Jul 02 '26 04:07

Denis Obydennykh


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

like image 35
marcelps Avatar answered Jul 02 '26 05:07

marcelps



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!