orilon

C# Check if email address is valid using regular expressions

Jun 4th, 2012
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.43 KB | None | 0 0
  1. using System.Text.RegularExpressions;
  2.  
  3. /// <summary>
  4. /// Determines whether source is a valid email address.
  5. /// </summary>
  6. /// <param name="source">The source</param>
  7. /// <returns>
  8. ///   <c>true</c> if source is valid email address; otherwise, <c>false</c>.
  9. /// </returns>
  10. public static bool IsValidEmailAddress(this string source)
  11. {
  12.     Regex regex = new Regex(@"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$");
  13.     return regex.IsMatch(source);
  14. }
Advertisement
Add Comment
Please, Sign In to add comment