验证电子邮件地址
<%
'验证Str是否是合法的电子邮件地址
Public Function ValidEmail(Str)
Dim StrArray, TempStr, I, TempChar
ValidEmail = True
StrArray = Split(Str, "@")
If UBound(StrArray) <> 1 Then
'如果不含有"@"或者含有多个"@",未能通过验证
ValidEmail = False
Exit Function
End If
For Each TempStr in StrArray
If Len(TempStr) <= 0 Then
'如果数组中的元素为空字符串,未能通过验证
ValidEmail = False
Exit Function
End If
For I = 1 to Len(TempStr)
TempChar = LCase(Mid(TempStr, I, 1))
If InStr("abcdefghijklmnopqrstuvwxyz_-.", TempChar) <= 0 And Not IsNumeric(TempChar) Then
'如果不是字母、数字以及"_"、"-"、"."等特殊字符,则为非法字符,未能通过验证
ValidEmail = False
Exit Function
End If
Next
If Left(TempStr, 1) = "." Or Right(TempStr, 1) = "." Then
'如果"."在字符串的最前或最后,未能通过验证
ValidEmail = False
Exit Function
End If
Next
If InStr(StrArray(1), ".") <= 0 Then
'如果@后没有".",未能通过验证
ValidEmail = False
Exit Function
End If
I = Len(StrArray(1)) - InStrRev(StrArray(1), ".")
If I <> 2 And I <> 3 Then
'如果"."位置错误,未能通过验证
ValidEmail = False
Exit Function
End If
If InStr(Str, "..") > 0 Then
'如果含有"..",未能通过验证
ValidEmail = False
End If
End Function
%>
--------------------------------
function ValidEmail(item)
{
var etext
var elen
var i
var aa
etext=item
elen=etext.length
if (elen<5)
return true;
i= etext.indexOf("@",0)
if (i==0 || i==-1 || i==elen-1)
return true;
else
{if (etext.indexOf("@",i+1)!=-1)
return true;}
if (etext.indexOf("..",i+1)!=-1)
return true;
i=etext.indexOf(".",0)
if (i==0 || i==-1 || etext.charAt(elen-1)=='.')
return true;
if ( etext.charAt(0)=='-' || etext.charAt(elen-1)=='-')
return true;
if ( etext.charAt(0)=='_' || etext.charAt(elen-1)=='_')
return true;
for (i=0;i<=elen-1;i++)
{ aa=etext.charAt(i)
if (!((aa=='.') || (aa=='@') || (aa=='-') ||(aa=='_') || (aa>='0' && aa<='9') || (aa>='a' && aa<='z') || (aa>='A' &&
aa<='Z')))
return true;
}
return false;
}
if (ValidEmail(form1.mail.value))
{
alert("请输入有效的Email地址!") ;
form1.mail.focus();
return false ;}
--------------------------------
<%
Function isemail(strng)
isemail = false
Dim regEx, Match
Set regEx = New RegExp
regEx.Pattern = "^/w+((-/w+)|(/./w+))*/@[A-Za-z0-9]+((/.|-)[A-Za-z0-9]+)*/.[A-Za-z0-9]+$"
regEx.IgnoreCase = True
Set Match = regEx.Execute(strng)
if match.count then isemail= true
End Function
%>
--------------------------------
function chkEmail(email)
on error resume next
dim i,l,pos1,pos2
chkEmail=true
if isnull(email) then chkEmail=false:exit function
pos1= instr(email,"@")
pos2=instrRev(email,".")
if not(pos1>0) or not (pos2>0) or pos1>pos2 then
chkEmail=false
end if
if err.number<>0 then err.clear
end function
--------------------------------
function chk_input(theform)
{
var email = theform.Email.value;
var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(/.[a-zA-Z0-9_-])+/;
flag = pattern.test(email);
if(!flag)
{
alert("email格式不正确!");
theform.Email.focus();
return false;
}
return (true);
}