Function to check the given text and regex pattern is match or not.

Code Snippet

public static bool IsMatch(string text, string pattern)
	if (!string.IsNullOrEmpty(text))
		text = text.Trim();
	Match mc = Regex.Match(text, pattern);
	bool isMatch = (mc.Success && (mc.Value == text));
	mc = null;
	return isMatch;

Sample Usage

string pattern = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
bool isMatch = IsMatch("[email protected]", pattern);


You need to import following line of code at the top of your class.

using System.Text.RegularExpressions;

author's photo

Author : Blue Cloud

Just a normal software developer who love to write code. Developing professional software since 1999. After working in the software industry for many years, I've started my own website to share knowledges and experiences.

blog comments powered by Disqus