Regular Expressions

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

Hello all,
I am looking for a regular expression for an email address. IE when a
user types in there email address I need to validate it to make sure it has
a @ and a host ie mydomain.com
Can anyone Help?

Thank you
Mark
 
here's a vb 6 example that validates based on the rfc...the pattern is
what's useful...modify for .net as needed.

hth,

steve


Function isEmailAddress(ByVal email As String) As Boolean
Dim reExpression As RegExp
Set reExpression = New RegExp
reExpression.Global = True
reExpression.Pattern =
"^(""[a-zA-Z0-9\$%&'\*\+\-/\?\^_`\{\|\}\~]*[^a-zA-Z0-9\$%&'\*\+\-/\?\^_`\{\|
\}\~""]+[a-zA-Z0-9\$%&'\*\+\-/\?\^_`\{\|\}\~]*"")|([a-zA-Z0-9\$%&'\*\+\-/\?\
^_`\{\|\}\~])([a-zA-Z0-9\$%&'\*\+\-/\?\^_`\{\|\}\~\.]*)@(\[((25[0-5]|2[0-4][
0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}|((([a-zA-Z0-9\-]+)\.)+))([a-zA-Z]{2
,}|(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\])$"
isEmailAddress = reExpression.Test(email)
End Function
 
Back
Top