I need to test in javascript the following formats (so I have a string and I must check if it’s valid or not)
XX:XX
value must be two integer (with two digits) separated by colon, the first one must be 0-23 and second 0-59 (it’s about time).
Second test is about date
DD.MM.YYYY
where DD is 2-digit representation of day, MM month and YYYY year – separated by dots. Can I also check is the date valid? So the user couldn’t type 45.02.9999 for example.
This can be accomplished with fairly straightforward RegEx.
The first to test time in 24-hour format would be:
The second to test date would be:
Which will allow dates up until 31.12.2019. It’s not smart enough to know how many days each month has (i.e. that 31.02.1999 is not a valid date), but should be good enough initial validation for most purposes.