您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

怎样用jQuery验证表单密码的一致性

2024/4/5 0:17:20发布16次查看
这次给大家带来怎样用jquery验证表单密码的一致性,用jquery验证表单密码的一致性的注意事项有哪些,下面就是实战案例,一起来看一下。
jquery 脚本
<script type="text/javascript"> function check_password() {   if ($(#password).val() != $(#checkpwd).val()){     alert(请保证两次输入密码的一致性!);     $(#checkpwd).focus();   } } function check_email() {   var reg = /\w+[@]{1}\w+[.]\w+/;   if (!reg.test($(#email).val())){     alert(请输入正确的email!);     $(#email).focus();   } } function check_phone() {   var reg = /^1[34578]\d{9}$/;   if (!reg.test($(#phone).val())){     alert(请输入正确的手机号!);     $(#phone).focus();   } } </script>
html 文件
<!doctype html> <html> <head>   <script src="jquery1.3.2.js"></script>   <meta http-equiv="content-type" content="text/html; charset=utf-8">   <title>注册界面</title> </head> <body>   <center>     <h1>用户注册</h1>     <form action="" method="post">       <table width="400px" cellspacing="0px" cellpadding="0px" border="1px">         <tr>           <td>用户名</td>           <td><input type="text" name="username" placeholder="用户名为3-12位字母数字或下划线组合" ></td>         </tr>         <tr>           <td>密 码</td>           <td><input type="password" name="password" placeholder="密码长度为6-12位的纯数字" id="password"></td>         </tr>         <tr>           <td>确认密码</td>           <td><input type="password" name="checkpwd" placeholder="密码长度为6-12位的纯数字" id="checkpwd" onchange="check_password()"></td>         </tr>         <tr>           <td>手机号码</td>           <td><input type="text" name="phone" placeholder="请输入正确的手机号码格式" id="phone" onchange="check_phone()"></td>         </tr>         <tr>           <td>邮箱</td>           <td><input type="email" name="email" placeholder="请输入正确邮箱格式" id="email" onchange="check_email()" required="required"></td>         </tr>         <tr>           <td colspan="2" style="text-align:center">             <input type="submit" value="注册">             <input type="reset" value="重置">           </td>         </tr>       </table>     </form>   </center> </body> </html>
运行结果:
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
怎么发掘空白处隐藏元素
ajax怎么实现下拉框无刷新联动
怎样确认jquery是否加载完毕
以上就是怎样用jquery验证表单密码的一致性的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product