/// /// Checks whether the provided e-mail address is in a valid format (as specified by RFC 822). /// /// The e-mail address to check. /// True if valid, otherwise false. public static bool CheckEmailValid(string emailAddress) { // Code by Jeremy Morton, 2010-09-30 // If e-mail address validity check fails, tell user... Invalid e-mail address format (Must be similar to user@domain.com) // Remember: .* is greedy by default! string reEmailAddressPattern = @" ^ # RFC 822 says e-mail addys consist of any CHAR except specials, SPACE and CTLs. # We also have the @ and . to seperate user or hostnames. # CHAR is ASCII 0-127(0x00-7F). SPACE is ASCII 32(0x20). # CTLs are ASCII 0-31(0x00-1F) and 127(0x7F). Specials are ( ) < > @ , ; : \ "" . [ ] # ASCII 127(0x7F) is a DEL control character - prudent to disallow this in an e-mail address. [^\x7F\x80-\xFF\x00-\x20\(\)\<\>\@\,\;\:\\\""\[\]]+ # ^ Username... even '(.)@host.com' is ok. \@ # ^ @ [^\x7F\x80-\xFF\x00-\x20\(\)\<\>\@\,\;\:\\\""\[\]\.]+ # ^ Host part 1 (no dots yet): 'blah@(host).com.com'. \. # ^ . [^\x7F\x80-\xFF\x00-\x20\(\)\<\>\@\,\;\:\\\""\[\]\.]+ [^\x7F\x80-\xFF\x00-\x20\(\)\<\>\@\,\;\:\\\""\[\]]* # ^ Host part 2 (remaining dots allowed): 'blah@host.(com.com)'. $ "; Regex reEmailAddress = new Regex(reEmailAddressPattern, RegexOptions.IgnorePatternWhitespace); return reEmailAddress.IsMatch(emailAddress); }