Syntax to use Regex for validation

Madhu.b.rokkam
Posted by Madhu.b.rokkam under C# category on | Points: 40 | Views : 1943
Regex regex = new Regex(YourSearchPattern);
bool isMatch = regex.IsMatch(YourSourceString);
Console.WriteLine("SourceString : {0} isMatch: {1}", YourSourceString, Convert.ToString(isMatch));

example

string YourSourceString = "Madhu";
string YourSearchPattern = "[a-z]{5}";
Regex regex = new Regex(YourSearchPattern);
bool isMatch = regex.IsMatch(YourSourceString);
Console.WriteLine("Source String: {0} isMatch: {1}", YourSourceString, Convert.ToString(isMatch));

output
Source String: Madhu isMatch: False

Comments or Responses

Login to post response