senzacionale
senzacionale

Reputation: 20916

regular expression dates

# Montag 28.03.2011
# Mi, 23.03.11

^([1-9]|0[1-9]|[12][0-9]|3[01])[-/.]([1-9]|0[1-9]|1[012])[- /.][0-9]{4} or with \d{2}[.]\d{2}[.]\d{4}

works for 28.03.2011 but not for 23.03.11. can i automatically add 20 before 11 if year is just 11?

Upvotes: 2

Views: 80

Answers (2)

Theun Arbeider
Theun Arbeider

Reputation: 5419

Why not use one of the methods available in the System.DateTime namespace? You could use DateTime.TryParseExact()

Upvotes: 1

Josnidhin
Josnidhin

Reputation: 12504

^([1-9]|0[1-9]|[12][0-9]|3[01])[-/.]([1-9]|0[1-9]|1[012])[- /.]([0-9]{4}|[0-9]{2})$

How about the above

By the way this is just pattern matching so it will match invalid dates too. eg:30.02.2011

Upvotes: 2

Related Questions