用JavaScript正则表达式实现Email验证
function checkEmail()
{
var reg = /\w+[@]\w+[.]\w+/;
var r = /[@]/;
var e = /[.]/;
var s_r = 0;
var s_e = 0;
var s_rCount = 0;
var s_eCount = 0;
var str;
str = document.all("test").value;
while(true)
{
s_r = str.search(r);
if(s_r != -1)
s_rCount ++;
else
break;
str = str.substring(s_r + 1,str.length);
}
str = document.all("test").value;
while(true)
{
s_e = str.search(e);
if(s_e != -1)
s_eCount ++;
else
break;
str = str.substring(s_e + 1,str.length);
}
str = document.all("test").value;
var s = str.search(reg);
alert(s);
alert(s_rCount);
alert(s_eCount);
if(s == 0 && s_rCount == 1 && s_eCount == 1)
alert("true");
else
alert("false");
}
{
var reg = /\w+[@]\w+[.]\w+/;
var r = /[@]/;
var e = /[.]/;
var s_r = 0;
var s_e = 0;
var s_rCount = 0;
var s_eCount = 0;
var str;
str = document.all("test").value;
while(true)
{
s_r = str.search(r);
if(s_r != -1)
s_rCount ++;
else
break;
str = str.substring(s_r + 1,str.length);
}
str = document.all("test").value;
while(true)
{
s_e = str.search(e);
if(s_e != -1)
s_eCount ++;
else
break;
str = str.substring(s_e + 1,str.length);
}
str = document.all("test").value;
var s = str.search(reg);
alert(s);
alert(s_rCount);
alert(s_eCount);
if(s == 0 && s_rCount == 1 && s_eCount == 1)
alert("true");
else
alert("false");
}
posted on 2006-06-29 14:26 我不是冷狐冲,我就是一酒壶 阅读(609) 评论(0) 编辑 收藏 举报