aurelia / validation

A validation plugin for Aurelia.
MIT License
132 stars 128 forks source link

ISO8601 Validator #131

Closed alexmills closed 8 years ago

alexmills commented 9 years ago

The Regex for date validation (from here) is very long and ugly:

/^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/

It would be awesome to have a specific date validator like this:

isISODate(date:string)
isISODate('1896-02-24T01:56:53.498Z')

If you're interested, I could fork and build it for you guys to consider?

jods4 commented 9 years ago

The worst part of a regex date validator, is that it cannot be completely correct anyway. What I mean by that is: a regex cannot take into account the edge cases such as February having 29 days in 2016 but not in 1900 but then again it does in 2000.

1900-02-29 is not a valid date but a regex will not tell you that. Heck, unless it's a really complicated regex I don't think it will even say that 2015-04-31 is not a valid date.

The cleanest code for dates is sometimes to simply parse and check if it's valid.

plwalters commented 8 years ago

Thanks for submitting this / commenting on this. At this time we are closing this because we have completely re-written and are deprecating the previous feature set. If you feel this should be re-opened please feel free to review this blog post and submit either again on this repository, or on the new validatejs bridge repository

Thanks again!