Regex 'Date Finder' expression validation

Hi,

I’m posting to validate a regular expression I have generated using this regex builder. I’m trying to search a string to see if it contains a date in the UK format dd/MM/yyyy.

The expression I generated is: [0-3][0-9](?:\/)[0-1][0-9](?:\/)[0-2][0-9][0-9][0-9]

It seems to work so far but I’m sure this can be improved on as I have limited experience with regular expressions. Any input would be appreciated, thank you.

Hi @PeterHeyburn

Try this

^(\d{1,2}).(\d{1,2}).(\d{4})

Thanks
Ashwin S

1 Like

@PeterHeyburn,

Try with this one,

(((0|1)[0-9]|2[0-9]|3[0-1])\/(0[1-9]|1[0-2])\/((19|20)\d\d))$
1 Like

Hi,

FYI, If you want to check strictly whether date string is valid, perhaps you should use IsDate function. For example, it can return exact if result 2/29 is valid or not, checking leap year.

Regards,

1 Like

Thanks, this was useful!

Thanks, I’m not just looking for dates in 2019 or 2020 though but I can use the first parts of your expression!

1 Like

Thanks, I will be reading a field where a date should be entered (but accepts any freetext) so I want to make sure there is a valid date in a proper format as I need to use it later in the process.

I will be able to use IsDate in future though!

2 Likes