-
Notifications
You must be signed in to change notification settings - Fork 379
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
dateISO could be more flexible #265
Comments
@stevegreatrex I'm thinking on using the same regex that jquery.validate uses: https://github.com/jzaefferer/jquery-validation/blob/master/src/core.js#L1136 as it seems more complete. |
Sounds like a sensible idea to me |
Othwerwise I can add some restrictions on month the least - 01-12. Currently for month can be anything from 0 to 99. I'll think more on this. |
Use the regex to pull the groups, parseInt and check? |
Pulling out groups and parseInt works but it can be done with regex too. So that months like 0 won't be accepted. |
IMO |
Fair enough for the time part, but regex only is hardly an acceptable solution. This validator still accepts things such as 2014-02-31, which is not a valid value. What's the point of having a |
@jods4 The assumptions you make are not correct.
I'm not aware of any validation framework that will attempt to check the value against a specific calendar, although it may exist. More over, if you use a date input in a browser that supports this input type then you won't be able to enter such value in the first place - so it doesn't make sense to make the validation too strict. Some tests to clarify this >> http://jsfiddle.net/dmwc84u7/ |
@crissdev Thanks for the information. I wasn't aware that the FWIW, I currently use my own date validator, based upon momentjs. I just checked and momentjs returns 'Invalid date' for |
@jods4 You may post the validator to User Contributed Rule wiki page if possible as we don't have a rule based on moment.js. Thanks. |
The validator contains additional bits of logic that are specific to my project, but to be honest it really comes down to: |
The dateISO binding is a bit too restrictive, in that it doesn't accept a time part, although it's part of the ISO specification.
Case where this means trouble: if you receive a date from ASP.NET Web API in JSON format, you get this by default:
2010-01-01T00:00:00
. Unfortunately it's refused by the validation plugin because dateISO only accepts yyyy-MM-dd.A second issue is that dateISO only uses a regexp, hence it accepts things such as 3000-99-99.
I suggest the following fix: only check the mandatory ISO part by modifying the regexp:
/^\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}/
(notice I removed the trailing $); and then delegate the work of figuring out if it's a correct date torules['date']
. This step also validates that the remaining of the expression is correct.New rule:
The text was updated successfully, but these errors were encountered: