How to validate date format of MM/dd/yyyy, am using ajax toolkit CalendarExtender for date picking, if able to validate the format of date in case not match want to show error msg Invalid date
Code
How to validate date format of MM/dd/yyyy, am using ajax toolkit CalendarExtender for date picking, if able to validate the format of date in case not match want to show error msg Invalid date
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Amit MohantyRank #112 · 20K reputationPosted Mar 15, 2023, 4:53 AM EDT
Check this
Tuhin PaulRank #7 · 71.9K reputationPosted Mar 15, 2023, 5:06 AM EDT
You can use a RegularExpressionValidator control:
1. Add a RegularExpressionValidator control to your ASP.NET page, below the TextBox and CalendarExtender controls:
2. In the RegularExpressionValidator control, set the ValidationExpression property to a regular expression that matches the MM/dd/yyyy format. The regular expression used in this example matches a date in the format MM/dd/yyyy, where MM is between 01 and 12, dd is between 01 and 31, and yyyy is a four-digit year between 1900 and 2099.
3. Set the ErrorMessage property of the RegularExpressionValidator control to the error message that should be displayed if the date format is not valid.
With these changes, the RegularExpressionValidator control will automatically validate the date format whenever a date is selected using the CalendarExtender control, and display an error message if the format is not valid.
Vishal JoshiRank #377 · 6.7K reputationPosted Mar 15, 2023, 3:24 AM EDT
Hello Manikandan
You can use RegularExpressionValidator to validate date format.
Thanks
Vishal
Rutuja Jadhav21 reputationPosted Mar 16, 2023, 1:37 AM EDT
You can use above code structure to validate date format.RegularExpressionValidator is for validate date format.
Tuhin PaulRank #7 · 71.9K reputationPosted Mar 16, 2023, 1:43 AM EDT
We can improve the following code as follows:
1) Add a label control to describe what the textbox is for. This makes it easier for users to understand what data they need to input. For example:
2) Consider adding a RequiredFieldValidator to ensure that the user inputs a date value.
3) Use a more precise regular expression to validate the date format. The current expression \d{2}/\d{2}/\d{4} will match any combination of 8 digits separated by slashes, but it does not actually validate that the input is a valid date. Consider using a regular expression that validates that the input is a valid date in the desired format.
This regular expression matches a valid date in MM/dd/yyyy format, including leap years and valid month and day ranges.
Jignesh KumarRank #91 · 22.9K reputationPosted Mar 16, 2023, 2:33 AM EDT
Try this one,