I am not expert in writing regular expressions so need your help. I want to validate date in "dd-MMM-yyyy" format i.e. 07-Jun-2012. I am using RegularExpressionValidator in asp.net.
Can anybody help me out providing the expression?
Thanks for sharing your time.
For dd-mm-yyyy format, use ^(0[1-9]|[12][0-9]|3[01])[- /.] (0[1-9]|1[012])[- /.] (19|20)\d\d$. You can find additional variations of these regexes in RegexBuddy's library.
The regex matches on a date with the MM/DD/YYYY format and a "Date of birth:" or "Birthday:" prefix (Year min: 1900, Year max: 2020). For example: Date of birth: 12/01/1900.
To validate a field with a Regex pattern, click the Must match pattern check box. Next, add the expression you want to validate against. Then add the message your users will see if the validation fails. You can save time for your users by including formatting instructions or examples in the question description.
The Validation (Regex) property helps you define a set of validation options for a given field. In general, this field property is used to perform validation checks (format, length, etc.) on the value that the user enters in a field. If the user enters a value that does not pass these checks, it will throw an error.
Using a DatePicker is probably the best approach. However, since that's not what you asked, here's an option (although it's case sensitive):
^(([0-9])|([0-2][0-9])|([3][0-1]))\-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\-\d{4}$
In addition, here's a place you can easily test Regular Expressions: http://www.regular-expressions.info/javascriptexample.html
Regex without leading zero in day.
^\d{1,2}-[a-zA-Z]{3}-\d{4}$
Update Regex with leading zero in day.
^\d{2}-[a-zA-Z]{3}-\d{4}$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With