Function Example To Validate An Email In ASP
Asp / / July 04, 2021
The following function is used to validate that an email address is correct in ASP.
function revMail (Mail)
'check valid address
'returns 1 for invalid addresses
'returns 0 for valid addresses
dim atCnt
revMail = 0
'chk length
if len (Mail) <5 then
' [email protected] should be the shortest possible address
revMail = 1
'check format
'check that it has an @
elseif instr (Mail, "@") = 0 then
revMail = 1
'check that it has a.
elseif instr (Mail, ".") = 0 then
revMail = 1
'check that it has no more than three characters after the.
elseif len (Mail) - instrrev (Mail, ".")> 4 then
revMail = 1
'that does not have _ after @
'elseif instr (Mail, "_") <> 0 and _
'instrrev (Mail, "_")> instrrev (Mail, "@") then
'revMail = 1
else
'that has only one @
atCnt = 0
for i = 1 to len (Mail)
if mid (Mail, i, 1) = "@" then
atCnt = atCnt + 1
end if
next
if atCnt> 1 then
revMail = 1
end if
'check character by character
for i = 1 to len (Mail)
if not isnumeric (mid (Mail, i, 1)) and _
(lcase (mid (Mail, i, 1)) lcase (mid (Mail, i, 1))> "z") and _
mid (Mail, i, 1) <> "_" and _
mid (Mail, i, 1) <> "." and _
mid (Mail, i, 1) <> "@" and _
mid (Mail, i, 1) <> "-" then
revMail = 1
end if
next
end if
end function
%>