本文實例講述了jquery使用正則表達(dá)式驗證email地址的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
<head>
<title>jquery使用正則表達(dá)式驗證email地址</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<script type="text/javascript" src="jquery-1.8.2.min.js"></script>
<script type="text/javascript">
$(function(){
$(":input[name='email']").blur(function(){
var email = $(this).val();
var reg = /\w+[@]{1}\w+[.]\w+/;
if(reg.test(email)){
$(":input[name='check']").val("email合法");
}else{
$(":input[name='check']").val("請輸入正確的email地址");
}
});
});
</script>
<style type="text/css">
h5{color:blue;}
</style>
</head>
<body>
<h5>jquery使用正則表達(dá)式驗證email地址</h5>
輸入Email地址:<input type="text" name="email" /><input type="text" name="check" style="border-width:0px;color:red" />
</body>
</html>
PS:這里再為大家提供2款非常方便的正則表達(dá)式工具供大家參考使用:
正則表達(dá)式在線測試工具:https://tool.zzvips.com/t/regex/
正則表達(dá)式在線生成工具:https://tool.zzvips.com/t/regcode/
希望本文所述對大家的jQuery程序設(shè)計有所幫助。