首先用编辑器(Dreamaver或记事本)建立index.asp文件(取名任意),输入以下代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>检测Email地址</title>
</head>
<body>
<form method="POST" action="emcheck.asp">
<p><input type="text" name="T1" size="20"><input type="submit" value="提交" name="B1">
<input type="reset" value="全部重写" name="B2"></p>
</form>
</body>
</html>
接着再建立emcheck.asp文件,输入以下代码:
<html>
<body>
<%
function IsValidEmail(email)
’判断EMAIL格式是否有效的函数
dim names, name, i, c
’Check for valid syntax in an email address.
IsValidEmail = true
names = Split(email, "@")
if UBound(names) <> 1 then
IsValidEmail = false
exit function
end if
for each name in names
if Len(name) <= 0 then
IsValidEmail = false
exit function
end if
for i = 1 to Len(name)
c = Lcase(Mid(name, i, 1))
if InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 and not IsNumeric(c) then
IsValidEmail = false
exit function
end if
next
if Left(name, 1) = "." or Right(name, 1) = "." then
IsValidEmail = false
exit function
end if
next
if InStr(names(1), ".") <= 0 then
IsValidEmail = false
exit function
end if
i = Len(names(1)) - InStrRev(names(1), ".")
if i <> 2 and i <> 3 then
IsValidEmail = false
exit function
end if
if InStr(email, "..") > 0 then
IsValidEmail = false
end if
end function
%>
<%
k=IsValidEmail(request("t1"))
if k=true then
response.write request("t1") & "邮件地址有效"
else
response.write request("t1") & "邮件地址无效"
end if
%>
</body>
</html>