'MVC 4 Regular Expression in View Model - date
I am creating MVC application and in my ViewModel I am trying to validate if input is of form DD/MM/YYYY and I do this like this:
[RegularExpression(@"^[0-9]+(/)+[0-9]+(/)+[1-9]$", ErrorMessage = "Input date has to be of form DD/MM/YYYY")]
How do I do it right?
Solution 1:[1]
If you want to keep your date as a string in the model then use the following
[RegularExpression(@"(((0|1)[0-9]|2[0-9]|3[0-1])\/(0[1-9]|1[0-2])\/((19|20)\d\d))$"]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Justin Marshall |
