邮箱验证功能的实现
1、邮箱输入的地方
<label> 电子邮箱:</label>
<input id="email" name="user.email" type="text" />
<span id="emailspan" ></span>
2、js中做验证
$("#email").bind('blur',function()
{
var userMail=$("#email").val();
if(userMail!="")
{
if(!checkEmail(userMail))
{
emailflag=false;
$("#emailspan").css("color","#ff0000");
$("#emailspan").html("邮箱格式不正确");
}
else
{
emailflag=true;
$("#emailspan").css("color","#43860c");
$("#emailspan").html("正确");
}
}
});
3、checkEmail ()
function checkEmail(email)
{
var pattern =/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
return pattern.test(email);
}
国泰民安