programming-examples/asp/More_Code_Snippets/Check email address using Regular expressions.asp

25 lines
1.1 KiB
Plaintext
Raw Permalink Normal View History

2019-11-18 14:25:58 +01:00
<%
'our function to check email addresses
'a fantastic list of regular expressions
Function CheckMail(strEmail)
'our variables
Dim objRegExp , blnValid
'create a new instance of the RegExp object , note we do not need Server.CreateObject("")
Set objRegExp = New RegExp
'this is our pattern we check .
objRegExp.Pattern = "^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
'store the result either true or false in blnValid
blnValid = objRegExp.Test(strEmail)
If blnValid Then
'display this if it is a vlid email address
Response.Write "This is a valid email address<br>"
Else
'display this if it is an invalid email address
Response.Write "That email address is invalid<br>"
End If
End Function
%>
<%CheckMail("validmail@email.com") 'correct email address %>
<%CheckMail("invalid1") 'incorrect , many errors%>
<%CheckMail("invalid+email.com") 'invalid + sign instead of @%>
<%CheckMail("invalid@email,com") 'invalid , sneaky uses a comma instead of a full stop%>