<script language="VBScript"><!--
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
--></script>
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
--></script>
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
--></script>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script>
function checkemail()
{
var flag=false;
for(i=0;i<document.form1.email.length;i++)
{
if(CharAt(i)='@')
{
flag=true;
break;
}
}
if(!flag)
alert("dssd");
}
</script></head><body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="">
<input type="text" name="email" onchange=checkemail()>
</form>
</body>
</html>
{
//去空格
// 邮件是中间有“@”和“.”并且最后一个“.”在“@”之后的字串
var isOk =false;
var iAt =s.indexOf("@");
var iDot =s.indexOf(".");
if(s==null){
}else if(s==""){
}else if(iAt<1 ||iAt==(s.length-1)){
}else if(iDot<1 ||iDot==(s.length-1)){
}else if(iAt>s.lastIndexOf(".")){
}else{
isOk =true;
}
}
{ flag=false;
var s;
s=document.form1.email.value;
for(i=0;i<s.length;i++)
if(s.charAt(i)=="@")
{ flag=true;
break;}
if(!flag)
alert("error:");
}</script>
<body>
<input type="text" name="email" onchange=checkemail()>
<head>
<script language=Javascript>
function check_it()
{
/*使用Regular expression
[email protected]
[email protected]
[email protected]
[email protected]
都会匹选
*/
var tomatch=/[A-Za-z0-9]\w{1,}@[A-Za-z0-9-]{1,}\.[A-Za-z]{3,}/
/*如果你想匹选
[email protected]的话
把tomatch=/[A-Za-z0-9]\w{1,}@[A-Za-z0-9-]{1,}\.[A-Za-z0-9-]{3,}\.[A-Za-z]{3,}/
*/
/*
你也可以把两种情况包含进来,或者匹选更多:如[email protected](有这样吧,可能有,哈哈)
tomatch=/[A-Za-z0-9]\w{1,}@[A-Za-z0-9-\.]{3,}/*/
var emadd=document.f1.t1.value;
if(tomatch.test(emadd))
{
window.alert(emadd+"E-mail Address OK");
return true;
}
else
{
window.alert(emadd+"E-mail address invalid");
return true;
}
}
</script>
</head>
<body onload=document.f1.t1.focus()>
<form name="f1" id="f1">
<input type="text" name="t1" id="t1">
<input type="button" name="b1" id="b1" value="Check" onclick=check_it()>
</form>
</body>
</html>
用这个将匹选所有:
var tomatch=/[A-Za-z0-9-_.]{1,}@[A-Za-z0-9-]{1,}\.[A-Za-z]{2,}/