form验证时常用的几个正则表达式
座机: d{3,4}-d{7,8}
手机号: /^1[34578][0-9]{9}$/ (86)?s+1[34578]d{0-9} (+86)?s*1[34578]d{9} ^(+86)?s*1[34578]d{9}$
邮箱: /^w+((-w+)|(.w+))*@[A-Za-z0-9]+((.|-)[A-Za-z0-9]+)*.[A-Za-z0-9]+$/
身份证: d{15}
密码必须包含数字,字母:
/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/i
/^(?=.*[a-zA-Z]+)(?=.*[0-9]+)[a-zA-Z0-9]+$/
判断Email地址格式是否正确
<input type="text" id="emailname"> <input type="submit" value="检测Email地址格式是否正确" class="is-email"> <script type="text/javascript"> $(".is-email").click(function(){ var email = $("#emailname").val(); if(email == ''){ alert("请输入您的邮箱"); return; }else if(email != "") { var reg = /^w+((-w+)|(.w+))*@[A-Za-z0-9]+((.|-)[A-Za-z0-9]+)*.[A-Za-z0-9]+$/; isok= reg.test(email ); if (!isok) { alert("邮箱格式不正确,请重新输入!"); return false; } }; alert("ok 输入正确"); }); </script>