Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace or remove date method #1063

Closed
jzaefferer opened this issue Mar 31, 2014 · 8 comments
Closed

Replace or remove date method #1063

jzaefferer opened this issue Mar 31, 2014 · 8 comments
Labels
Core Date stale Used to mark stale issues

Comments

@jzaefferer
Copy link
Collaborator

This causes a ton of issues:

<input type="date">

Currently the only reasonable way to avoid issues with the native date method messing up validation is to remove the method:

delete $.validator.methods.date;

Then using, if necessary, a proper date validation method. An alternative is to ignore date inputs:

ignore: "input[type='date']"

The method as-is needs to be removed, or replaced with something that actually works. Maybe using Globalize, see #581.

@neogic
Copy link

neogic commented Mar 31, 2014

Dear US developers - you are the only country (alongside freakin Belize - combined making up less than 6% of world population) in the world that uses mm/dd/yy. Please stop assuming this is the only format in use for dates with slashes {facepalm} http://en.wikipedia.org/wiki/Date_format_by_country#Map

The jQuery Validation > Date demo page still fails for dd/mm/yy dates in Chrome BTW: http://jqueryvalidation.org/date-method - try 13/12/14. We posted a workaround a year ago - see issue #549.

@stijnherreman
Copy link

I've spent some time recently researching HTML5's date and time input types. Over the years, various browsers have added and dropped support. Implementations are often partial, they differ per browser and they can add undesired behaviour.
The future of these types in the WHATWG and W3C specs is uncertain.

Another pain point is the unreliable browser support for datetime parsing, third-party libraries like Moment.js need to be used.

I'll be avoiding these types for the time being, and I wanted to share my findings so you can evaluate the future of related features in this project.

@hozza
Copy link

hozza commented Jan 13, 2015

Is there a way to replace the date method with the dateISO method?

Edit: Yes there is, this fixes the localisation issue for me, by using the global standard, without having to change any HTML input types.

$.validator.addMethod("date", $.validator.methods.dateISO);

@jzaefferer
Copy link
Collaborator Author

You can also reuse the default message:

$.validator.addMethod("date", $.validator.methods.dateISO, $.validator.messages.date);

@dubonzi
Copy link

dubonzi commented Mar 6, 2015

This validates dd/mm/yyyy dates.
Added this to jquery.validate.js

Reference(Regex): Regex to validate date format dd/mm/yyyy

dateBR: function( value, element ) {
            return this.optional(element) || /^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/.test(value);
        }

messages: {
dateBR: "Data inválida."
}

classRuleSettings: {
dateBR: {dateBR: true}
}

Usage:

 $( "#editarDadosCliente" ).validate({
            rules: {
                txtdataLeiAutorizativa: {
                    dateBR: true
                }
            }
        });

@cjba7
Copy link

cjba7 commented Feb 24, 2016

Guys is this still an issue? Had a look around and still cant find a decent way to check for dd/mm/yyyy and then also have a custom method to check its over 18 years ago.

@aodysseos aodysseos mentioned this issue Feb 28, 2018
@aodysseos
Copy link

This is how I validated UK dates.

function ukDateValidation( value, element ) {
        return this.optional(element) || /^(?:(?:(?:(?:31\/(?:0?[13578]|1[02]))|(?:(?:29|30)\/(?:0?[13-9]|1[0-2])))\/(?:1[6-9]|[2-9]\d)\d{2})|(?:29\/0?2\/(?:(?:(1[6-9]|[2-9]\d)(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:0?[1-9]|1\d|2[0-8])\/(?:(?:0?[1-9])|(?:1[0-2]))\/(?:(?:1[6-9]|[2-9]\d)\d{2}))$/.test(value);
    }

$.validator.addMethod("UKDate", ukDateValidation, "Please enter a date in the format dd/mm/yyyy.");

$.validator.addClassRules("date", { UKDate: true });

@jquery-validation jquery-validation deleted a comment from nukec Mar 1, 2018
@stale
Copy link

stale bot commented Jun 5, 2018

This issue/proposal has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and one of the maintainers will (try!) to follow up.
Thank you for contributing :)

@stale stale bot added the stale Used to mark stale issues label Jun 5, 2018
@stale stale bot closed this as completed Jun 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core Date stale Used to mark stale issues
Projects
None yet
Development

No branches or pull requests

8 participants