I am trying to validate a date entered into a text box. There is an input mask on the textbox which forces input of xx/xx/xxxx. I am trying to use a regular expression valid
We can use a CustomValidator and use the override the ServerValidate method to check the TryParse!
This would be correct regular expression to use for date format dd/mm/yyyy
^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d$
Kettenbach had a problem. His co-worker suggested using regexs. Kettenbach then had two problems.
As others have said, use DateTime.TryParse
or DateTime.TryParseExact
on a custom validator and save yourself the nightmare that is regex :)
This isn't really an answer, but couldn't you use DateTime.Parse
or DateTime.TryParse to check that the date is correct?
Either that or use a DateTime
control to make sure it's impossible to enter data that isn't a DateTime. There's lots of JavaScript out there on this subject.