Regular expression for validating date in javascript

Rated 3.99/5 based on 946 customer reviews

I was searching the web for Java Script date validation code.

I didn’t see Chris Hogben’s article initially, but he used the right algorithm.

For instance, here is a basic regex that describes any time in the 24-hour HH/MM format. Most code editors support regex-based find/replace operations.

regular expression for validating date in javascript-47

regular expression for validating date in javascript-24

regular expression for validating date in javascript-79

It’s not even full client-side validation – it’s just a subtle usability enhancement, implemented in an accessible way, which (as I discovered while testing the script) is almost identical to something that Firefox now does natively!Such a script is beyond the scope of this article, but if you wanted to develop it further, all of the basic blocks are there – testing whether a field should be validated, validating a field against a pattern and/or required, and binding trigger events.I have to confess, I’m not sure it’s really worth it!For example, I’ve seen forms where it’s impossible to ) to force the focus to stay inside the field until it’s valid.This is very poor usability, and directly contravenes accessibility guidelines.

Leave a Reply