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

minor change to date validation #70

Closed
jzaefferer opened this issue Apr 2, 2011 · 2 comments
Closed

minor change to date validation #70

jzaefferer opened this issue Apr 2, 2011 · 2 comments

Comments

@jzaefferer
Copy link
Collaborator

Since datejs and others make tweaks to the Date.parse, and it's
specifically easier to override in terms of prototypal enhancement in
JS, I'd suggest updating the date validation to the following...

   // http://docs.jquery.com/Plugins/Validation/Methods/date
   date: function(value, element) {
           return this.optional(element) || !/Invalid|NaN/.test(Date.parse(value) || new Date(value));
   },

This should support situations where Date and/or Date.parse are enhanced
to handle additional parsing. :)

@fbuchinger
Copy link
Contributor

I am also annoyed by the default date validator, since it does only basic syntax checking, (e.g. a german date like "99.99.2011" validates). But do we really need to depend on date.js for enhanced checking?

Since an "invalid" date object like (new Date (2008,99,99)) is converted to a future/past date (in this case to 8th march 2016), you can use the following algorithm:

  1. create new Date object enteredDate from the entered year, month, day values
  2. check if enteredDate.getFullYear() == enteredYear && !!enteredDate.getFullYear() (prevent falsy values,)
  3. check if enteredDate.getMonth() == enteredMonth-- && !!enteredDate.getMonth()
  4. same goes for Day (Date)

this could happen in a simple external function that is invoked by all culture-specific date validators once they extracted
the year, month, day values from the entered date.

@jzaefferer
Copy link
Collaborator Author

Superseded by #581

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants