Sunday, 10 February 2013

Check Regex Match Programmaticaly Using C#

Check Regex Match Programmaticaly Using C#

We always get into situation when we have to check the validation of the particular string using regex...
We have a separate validation control for this ie., Regular Expression Validator.. But It is not always feasible to use it.. So Here I am with an alternative..

I am going to validate the date in mm/dd/yyyy format using Regex Programmatically:

string date="02/28/2013";
Regex regex = new Regex(@"^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$");
Match match = regex.Match(date);
if (match.Success)
// Your Insert Code
// Show Error Message

No comments:

Post a Comment

Thank You for Your Comments. We will get back to you soon.

back to top