2015/02/04

Email validation with regulara expressions in C#

static string cutEmail(string str)
{
string email = null;
Regex rx = new Regex(@"(?<email>[\w!#$%&'*+\-/=?\^_`{|}~]+(\.[\w!#$%&'*+\-/=?\^_`{|}~]+)*@((([\-\w]+\.)+[a-zA-Z]{2,4})|(([0-9]{1,3}\.){3}[0-9]{1,3})))", RegexOptions.None);
Match match = rx.Match(str);
if (match.Success)
email = match.Groups["email"].Value;
return email;
}
view raw gistfile1.cs hosted with ❤ by GitHub

No comments:

Post a Comment