要求:1.符合中国所有的邮件地址习惯
2.前面要让带“.”的通过。比如:[email protected]为正常邮件地址我自己写了个代码,请大家帮忙验证一下,并让带“.”(@前面)的地址通过
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>email</title>
<script type="text/javascript">
function isemail(address)
{
var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
if(pattern.test(address))
{
alert("邮件合法");
}
else
{
alert("邮件不合法");
}
}
</script>
</head><body>
<form name="form1" method="get" action="">
<input name="email" id="emailId" type="text" value="" />
<input name="确定" value="确定" type="button" onclick="javascript:isemail(document.getElementById('emailId').value);" />
</form></body>
</html>
2.前面要让带“.”的通过。比如:[email protected]为正常邮件地址我自己写了个代码,请大家帮忙验证一下,并让带“.”(@前面)的地址通过
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>email</title>
<script type="text/javascript">
function isemail(address)
{
var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
if(pattern.test(address))
{
alert("邮件合法");
}
else
{
alert("邮件不合法");
}
}
</script>
</head><body>
<form name="form1" method="get" action="">
<input name="email" id="emailId" type="text" value="" />
<input name="确定" value="确定" type="button" onclick="javascript:isemail(document.getElementById('emailId').value);" />
</form></body>
</html>
请大家帮忙弄弄。。本人不懂正则语法……
--------------------------------------------------------------------------------
比如:[email protected]合法
但是[email protected] ,[email protected]均不合法。
{
var pattern = /[a-zA-Z0-9_-]+[\.]*[a-zA-Z0-9_-]*[@][a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+/;
if(pattern.test(address))
{
alert("邮件合法");
}
else
{
alert("邮件不合法");
}
}
isemail('[email protected]');