jquery使用正则表达式验证email地址的方法
本文实例讲述了jquery使用正则表达式验证email地址的方法。分享给大家供大家参考。具体实现方法如下:
<html>
<head>
<title>jquery使用正则表达式验证email地址</title>
<metahttp-equiv="content-type"content="text/html;charset=utf-8"/>
<scripttype="text/javascript"src="jquery-1.8.2.min.js"></script>
<scripttype="text/javascript">
$(function(){
$(":input[name='email']").blur(function(){
varemail=$(this).val();
varreg=/\w+[@]{1}\w+[.]\w+/;
if(reg.test(email)){
$(":input[name='check']").val("email合法");
}else{
$(":input[name='check']").val("请输入正确的email地址");
}
});
});
</script>
<styletype="text/css">
h5{color:blue;}
</style>
</head>
<body>
<h5>jquery使用正则表达式验证email地址</h5>
输入Email地址:<inputtype="text"name="email"/><inputtype="text"name="check"style="border-width:0px;color:red"/>
</body>
</html>
PS:这里再为大家提供2款非常方便的正则表达式工具供大家参考使用:
JavaScript正则表达式在线测试工具:
http://tools.jb51.net/regex/javascript
正则表达式在线生成工具:
http://tools.jb51.net/regex/create_reg
希望本文所述对大家的jQuery程序设计有所帮助。