I am trying to collect a regular expression that matches any part of a valid date, while the part starts from the front. The actual date is defined as DD / MM / YYYY from 1900 <= YYYY <2100. I donβt care about leap years, days in the months are different depending on the month, etc.
The goal is to provide validation feedback to users as they are entered, but only when they are on the wrong track. I believe this improves user experience.
So for example:
'1' matches (as eg 12/12/1999 is a valid date) '4' does not match '04' matches '12/12/' matches
This is where I got it:
^(([0123]\d?)|([0123]\d\/[01]?)|([0123]\d\/[01]\d\/?)|([0123]\d\/[01]\d\/(1|2|19\d{0,2}|20\d{0,2})))$
Any simpler ways to do this with regex?
refiddle
javascript regex validation
chrisvdb
source share