interviews.dotnetthread.com

↑ Grab this Headline Animator

Wednesday, July 2, 2008

How to perform regular expression validations in C# code behind(i.e, without using regular expression validator control).

using System.Text.RegularExpressions;
//Some regular expression as ex: email Id validator
string expression = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";

System.Text.RegularExpressions.Match match =
Regex.Match(txtEmail.Text.Trim(), expression, RegexOptions.IgnoreCase);

if(match.Success)
MessageBox.Show("Success");
else
MessageBox.Show("Fail");

Submit this story to DotNetKicks

No comments:

Post a Comment

Post your comments/questions/feedback for this Article.

 

Latest Articles