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
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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh KumarPosted Mar 16, 2023, 6:33 AM
Try this one,
Tuhin PaulPosted Mar 16, 2023, 5:43 AM
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.
Rutuja JadhavPosted Mar 16, 2023, 5:37 AM
You can use above code structure to validate date format.RegularExpressionValidator is for validate date format.
Tuhin PaulPosted Mar 15, 2023, 9:06 AM
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.
Amit MohantyPosted Mar 15, 2023, 8:53 AM
Check this
Vishal JoshiPosted Mar 15, 2023, 7:24 AM
Hello Manikandan
You can use RegularExpressionValidator to validate date format.
Thanks
Vishal