C#

Regular expression for date

Posted on

I was looking for the perfect regex to validate a date. The examples I found on the internet where all not good enough. If you try validating 29/02/2010 it should give a fault but it didn’t so I created my own regex. The best regular expression I can think of right now is this: ^(((0?[1-9]|[12]\d|3[01])[\/](0?[13578]|1[02])[\/]((1[6-9]|[2-9]\d)?\d{2}|\d))|((0?[1-9]|[12]\d|30)[\/](0?[13456789]|1[012]) […]