function isEmail (s)
{
// is s Empty?
if (isEmpty(s))
{
window.alert("输入的E-mail地址不能为空,请输入!");
mobj = eval("document.wizard.tr_email");
mobj.focus()
mobj.select()
return false;
}
//is s contain whitespace
if (isWhitespace(s))
{
window.alert("输入的E-mail地址中不能包含空格符,请重新输入!");
mobj = eval("document.wizard.tr_email");
mobj.focus()
mobj.select()
return false;
} // there must be >= 1 character before @, so we
// start looking at character position 1
// (i.e. second character)
var i = 1;
var len = s.length; if (len > 50)
{
window.alert("email地址长度不能超过50位!");
mobj = eval("document.wizard.tr_email");
mobj.focus()
mobj.select()
return false;
}
pos1 = s.indexOf("@");
pos2 = s.indexOf(".");
pos3 = s.lastIndexOf("@");
pos4 = s.lastIndexOf(".");
//check '@' and '.' is not first or last character
if ((pos1 <= 0)||(pos1 == len)||(pos2 <= 0)||(pos2 == len))
{
window.alert("请输入有效的E-mail地址!");
mobj = eval("document.wizard.tr_email");
mobj.focus()
mobj.select()
return false;
}
else
{
//check @. or .@
if( (pos1 == pos2 - 1) || (pos1 == pos2 + 1)
|| ( pos1 != pos3 ) //find two @
|| ( pos4 < pos3 ) ) //. should behind the '@'
{
window.alert("请输入有效的E-mail地址!");
mobj = eval("document.wizard.tr_email");
mobj.focus()
mobj.select()
return false;
}
} if ( !isCharsInBag( s, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@"))
{
window.alert("email地址中只能包含字符ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@\n" + "请重新输入" );
mobj = eval("document.wizard.tr_email");
mobj.focus()
return false;
}
//is s contain invalid characters
/*
var badChar = "><,[]{}?/+=|\\'\":;!#$%^&()`";
if ( isCharsInBag( s, badChar))
{
alert("请不要在email地址中输入字符 " + badChar + "\n" );
alert("请重新输入" );
return false;
}
*/
return true;
}
{
// is s Empty?
if (isEmpty(s))
{
window.alert("输入的E-mail地址不能为空,请输入!");
mobj = eval("document.wizard.tr_email");
mobj.focus()
mobj.select()
return false;
}
//is s contain whitespace
if (isWhitespace(s))
{
window.alert("输入的E-mail地址中不能包含空格符,请重新输入!");
mobj = eval("document.wizard.tr_email");
mobj.focus()
mobj.select()
return false;
} // there must be >= 1 character before @, so we
// start looking at character position 1
// (i.e. second character)
var i = 1;
var len = s.length; if (len > 50)
{
window.alert("email地址长度不能超过50位!");
mobj = eval("document.wizard.tr_email");
mobj.focus()
mobj.select()
return false;
}
pos1 = s.indexOf("@");
pos2 = s.indexOf(".");
pos3 = s.lastIndexOf("@");
pos4 = s.lastIndexOf(".");
//check '@' and '.' is not first or last character
if ((pos1 <= 0)||(pos1 == len)||(pos2 <= 0)||(pos2 == len))
{
window.alert("请输入有效的E-mail地址!");
mobj = eval("document.wizard.tr_email");
mobj.focus()
mobj.select()
return false;
}
else
{
//check @. or .@
if( (pos1 == pos2 - 1) || (pos1 == pos2 + 1)
|| ( pos1 != pos3 ) //find two @
|| ( pos4 < pos3 ) ) //. should behind the '@'
{
window.alert("请输入有效的E-mail地址!");
mobj = eval("document.wizard.tr_email");
mobj.focus()
mobj.select()
return false;
}
} if ( !isCharsInBag( s, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@"))
{
window.alert("email地址中只能包含字符ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@\n" + "请重新输入" );
mobj = eval("document.wizard.tr_email");
mobj.focus()
return false;
}
//is s contain invalid characters
/*
var badChar = "><,[]{}?/+=|\\'\":;!#$%^&()`";
if ( isCharsInBag( s, badChar))
{
alert("请不要在email地址中输入字符 " + badChar + "\n" );
alert("请重新输入" );
return false;
}
*/
return true;
}
$result = ereg('^([a-zA-Z0-9_]|\\-|\\.)+'.'@'.
'(([a-zA-Z0-9_]|\\-)+\\.)+'.
'[a-zA-Z0-9]{2,4}$',
$email);
return ($result)? true: false;
}
是的
function isEmail($string)
{
if (!preg_match("/^[0-9a-z_-]+@[a-z0-9_-]+(\.{1}[a-z]+){1}(\.{1}[a-z]+)?$/i",$string))
{
return false;
}
return true;
}
按照上面的算法,就算错,因为zhang 和san之间有个 "."2, 结尾.com可以最多就4位吧是不是,一般情况比如[email protected]
有没有多于4位的情况?如果没有,能否规定结尾的长度?3,"@"和"."之间最少也要有3个字母或数字吧?是否也要规定?4, 结尾能有数字吗?也就是没有[email protected]的情况能出现吧?谢谢大家再次费心了。
function CheckEmail($email)
{
if(ereg("^[a-zA-Z0-9\-\.\_]+@[a-zA-Z0-9]+\.[a-zA-Z0-9]+$",$email))
return true;
else
return false;
}
re = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i;然后用字符串来match(re)
正则式就够了楼主的担心完全可以不必,按照RFC标准,Email地址格式没有你说的那些限制,用户名也没.的。邮件服务器对用户名判断时候不一定用什么样的认证方式,可能是系统用户,可能是数据库,可能是LDAP。还有后缀的长度,没人规定邮件地址的后缀多长。[email protected]只是现在人习惯的邮件地址,其实早期的Email更多的是本服务器内用户发送的,只要RCPT TO到一个用户名就可以了。