While working on the localization of our entire suite of systems & applications we needed a regular expression that would validate user input for a date. So depending on the user locale/language the date format changes. We needed three: Day first(Europe) DD.MM.YYYY, Month first MM/DD/YYYY (US) and year first YYYY/MM/DD (chinese).
So we set the value of the Threads current context and used the DateFormatInfo class from there to determine which format to use.
Then we found a regEx that worked for US (ref.1) and modified it for out use.
^(?
(?
(?
[- /.]{1} #seperator
(?
|
(?
[- /.]{1} #seperator
(?
|
(?
[- /.]{1} #seperator
(?
[- /.]{1} #seperator
(?
(?
|
(?
[- /.]{1} #seperator
(?
[- /.]{1} #seperator
(?
)$
|
#German
^(?
(?
(?
[- /.]{1} #seperator
(?
|
(?
[- /.]{1} #seperator
(?
|
(?
[- /.]{1} #seperator
(?
)
[- /.]{1} #seperator
(?
(?
|
(?
[- /.]{1} #seperator
(?
[- /.]{1} #seperator
(?
(?
(?
|
(?
(?
)$
|
#CHN
^(?
(?
(?
[- /.]{1} #seperator
(?
(?
[- /.]{1} #seperator
(?
|
(?
[- /.]{1} #seperator
(?
|
(?
[- /.]{1} #seperator
(?
|
(?
[- /.]{1} #seperator
(?
[- /.]{1} #seperator
(?
)$
-------------------------------
Ref.1 - by Dany Lauener; http://regexlib.com/UserPatterns.aspx?authorId=81355952-f53d-4142-bc5c-aab2beae19f3; search for "MM/dd/yyyy with 100% leap years. Valid since year 1900"