Regular Expressions help

Hi,
I’m new to regular expressions and I’m trying to validate a date so that only dates from 2017 onwards are allowed to be selected. I found a regex online that works with my code, but I’m unsure as to what I change to get it so that it only accepts 2017. Also, it only works in Chrome. The validation doesn’t work in FireFox. Any way to fix that?

Any help is much appreciated, thank you. Apologies if this is in the wrong forum.

/^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$/g;

Regex doesn’t strike me as the best tool for this task. I’d use regex to find the date and then convert it to a Date object

If you’re intentionally looking to make things difficult for yourself then you should probably also solve it by yourself. To debug it you can to divide it into smaller parts to test individually and narrow down where the problem is. www.regex101.com might be useful as an aid in reading the regex

1 Like