javascript邮箱格式验证

用户在注册时往往需要邮箱验证,众所周知 我们所用的邮箱是有一定格式的,那么这个格式我们该如何控制呢?下面就给出了源代码来验证邮箱的格式..

<html>
<head>
<script type="text/javascript">
function validate_email(field,alerttxt)
{
with (field)
{
apos=value.indexOf("@")
dotpos=value.lastIndexOf(".")
if (apos<1||dotpos-apos<2) 
  {alert(alerttxt);return false}
else {return true}
}
}

function validate_form(thisform)
{
with (thisform)
{
if (validate_email(email,"Not a valid e-mail address!")==false)
  {email.focus();return false}
}
}
</script>
</head>

<body>
<form action="submitpage.htm"onsubmit="return validate_form(this);" method="post">
Email: <input type="text" name="email" size="30">
<input type="submit" value="Submit"> 
</form>
</body>

</html>
 

猜你喜欢

转载自dxl-xiaoli.iteye.com/blog/1129463