'''
''' Verifies the string passed to the function as being a valid e-mail address.
'''
''' The string to check as being a valid e-mail address.
''' True if valid, false otherwise.
Public Shared Function VerifyEmail(ByVal emailToVerify As String) As Boolean
' Code by Jeremy Morton, 2010-05-29
' If e-mail address validity check fails, tell user... Invalid e-mail address format (Must be similar to user@domain.com)
Dim reEmailAddress As New Regex( _
"^ # RFC 822 says e-mail addys consist of any CHAR except specials, SPACE and CTLs." & vbCrLf & _
" # We also have the @ and . to seperate user or hostnames." & vbCrLf & _
" # CHAR is ASCII 0-127(0x00-7F). SPACE is ASCII 32(0x20)." & vbCrLf & _
" # CTLs are ASCII 0-31(0x00-1F) and 127(0x7F). Specials are ( ) < > @ , ; : \ "" . [ ]" & vbCrLf & _
" # ASCII 127(0x7F) is a DEL control character - prudent to disallow this in an e-mail address." & vbCrLf & _
"[^\x7F\x80-\xFF\x00-\x20\(\)\<\>\@\,\;\:\\\""\[\]]+" & vbCrLf & _
" # ^ Username... even '(.)@host.com' is ok." & vbCrLf & _
"\@" & vbCrLf & _
" # ^ @" & vbCrLf & _
"[^\x7F\x80-\xFF\x00-\x20\(\)\<\>\@\,\;\:\\\""\[\]\.]+" & vbCrLf & _
" # ^ Host part 1 (no dots yet): 'blah@(host).com.com'." & vbCrLf & _
"\." & vbCrLf & _
" # ^ ." & vbCrLf & _
"[^\x7F\x80-\xFF\x00-\x20\(\)\<\>\@\,\;\:\\\""\[\]\.]+" & vbCrLf & _
"[^\x7F\x80-\xFF\x00-\x20\(\)\<\>\@\,\;\:\\\""\[\]]*" & vbCrLf & _
" # ^ Host part 2 (remaining dots allowed): 'blah@host.(com.com)'." & vbCrLf & _
"$" _
, RegexOptions.IgnorePatternWhitespace)
If (reEmailAddress.IsMatch(emailToVerify)) Then
Return True
Else
Return False
End If
End Function