Validform验证身份证 js调用asp.net后台ajaxurl知识点分享,代码如下:
<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeBehind="reg.aspx.cs" Inherits="DTcms.Web.demo.yxjg.WebForm1" %> <!DOCTYPE html> <html class="ui-page-login"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" /> <title>云下健管</title> <link href="css/mui.min.css" rel="stylesheet" /> <link href="css/style.css" rel="stylesheet" /> <script src="../../scripts/jquery/jquery1.9.1/jquery-1.9.1.min.js"></script> <script src="../../scripts/jquery/Validform_v5.3.2_min.js"></script> <link rel="stylesheet" href="http://weixin.yoby123.cn/weui/style/weui.css" /> <link rel="stylesheet" href="http://weixin.yoby123.cn/weui/style/weui2.css" /> <link rel="stylesheet" href="http://weixin.yoby123.cn/weui/style/weui3.css" /> <script>jQuery.noConflict()</script> <script src="http://weixin.yoby123.cn/weui/zepto.min.js"></script> <style> .area { margin: 20px auto 0px auto; } .mui-input-group:first-child { margin-top: 20px; } .mui-input-row label { padding: 11px 5px 11px 5px; width: 32%; } .mui-input-row label ~ input, .mui-input-row label ~ select, .mui-input-row label ~ textarea { width: 68%; } .mui-checkbox input[type=checkbox], .mui-radio input[type=radio] { top: 6px; } .mui-content-padded { margin-top: 25px; } .mui-btn { padding: 10px; } .mui-checkbox, .mui-radio { margin-top: 20px; } .mui-checkbox span { line-height: 40px; color: #4a7ed7; } .mui-checkbox span a { color: #37d768; } .mui-input-row input.fsyzm { font-size: 12px; position: absolute; right: 0; width: 85px; line-height: 24px; color: #4a7ed7; text-align: center; padding: 5px 0; margin-right: 2px; margin-top: 2px; border-left: 1px solid #0062cc; } </style> </head> <body> <script> // 当页面ready的时候,执行回调: $(function () { //alert('Ready to Zepto!1') }); jQuery(document).ready(function () { // 这里是使用 jQuery $ 的代码 jQuery("#form1").Validform({ btnSubmit: "#reg", tiptype: 1, beforeSubmit: function (curform) { __doPostBack('reg', ''); //return false; //在验证成功后,表单提交前执行的函数,curform参数是当前表单对象。 //这里明确return false的话表单将不会提交; }, tiptype: function (msg, o, cssctl) { //alert(o.type); if (o.type == 3) {//验证失败才提示 $.alert(msg, "注意!"); } //return false; //msg:提示信息; //o:{obj:*,type:*,curform:*}, //obj指向的是当前验证的表单元素(或表单对象,验证全部验证通过,提交表单时o.obj为该表单对象), //type指示提示的状态,值为1、2、3、4, 1:正在检测/提交数据,2:通过验证,3:验证失败,4:提示ignore状态, //curform为当前form对象; //cssctl:内置的提示信息样式控制函数,该函数需传入两个参数:显示提示信息的对象 和 当前提示的状态(既形参o中的type); }, datatype: {//传入自定义datatype类型【方式二】; "idcard": function (gets, obj, curform, datatype) { //该方法由佚名网友提供; var Wi = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1];// 加权因子; var ValideCode = [1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2];// 身份证验证位值,10代表X; if (gets.length == 15) { return isValidityBrithBy15IdCard(gets); } else if (gets.length == 18) { var a_idCard = gets.split("");// 得到身份证数组 if (isValidityBrithBy18IdCard(gets) && isTrueValidateCodeBy18IdCard(a_idCard)) { return true; } return false; } return false; function isTrueValidateCodeBy18IdCard(a_idCard) { var sum = 0; // 声明加权求和变量 if (a_idCard[17].toLowerCase() == 'x') { a_idCard[17] = 10;// 将最后位为x的验证码替换为10方便后续操作 } for (var i = 0; i < 17; i++) { sum += Wi[i] * a_idCard[i];// 加权求和 } valCodePosition = sum % 11;// 得到验证码所位置 if (a_idCard[17] == ValideCode[valCodePosition]) { return true; } return false; } function isValidityBrithBy18IdCard(idCard18) { var year = idCard18.substring(6, 10); var month = idCard18.substring(10, 12); var day = idCard18.substring(12, 14); var temp_date = new Date(year, parseFloat(month) - 1, parseFloat(day)); // 这里用getFullYear()获取年份,避免千年虫问题 if (temp_date.getFullYear() != parseFloat(year) || temp_date.getMonth() != parseFloat(month) - 1 || temp_date.getDate() != parseFloat(day)) { return false; } return true; } function isValidityBrithBy15IdCard(idCard15) { var year = idCard15.substring(6, 8); var month = idCard15.substring(8, 10); var day = idCard15.substring(10, 12); var temp_date = new Date(year, parseFloat(month) - 1, parseFloat(day)); // 对于老身份证中的你年龄则不需考虑千年虫问题而使用getYear()方法 if (temp_date.getYear() != parseFloat(year) || temp_date.getMonth() != parseFloat(month) - 1 || temp_date.getDate() != parseFloat(day)) { return false; } return true; } } } }); }); function settimesms(obj) { if (jQuery('#mobile').val() == '') { $.alert("手机号不能为空!", "注意!"); return false; } if (jQuery('#mobile').attr('class') == 'mui-input-clear mui-input Validform_error') { $.alert("手机号验证失败!", "注意!"); return false; } jQuery.ajax({ url: "yxjgHandler.ashx?mobile=" + jQuery('#mobile').val() + "&type=regsms", async: false }); //先执行发送验证码 settime(obj);//调用验证码方法 } var countdown = 60; function settime(obj) { if (countdown == 0) { obj.removeAttribute("disabled"); obj.value = "获取验证码"; countdown = 60; return; } else { obj.setAttribute("disabled", true); obj.value = "重新发送(" + countdown + ")"; countdown--; } setTimeout(function () { settime(obj) } , 1000) } </script> <script type="text/javascript"> <!-- var theForm = document.forms['form1']; if (!theForm) { theForm = document.form1; } function __doPostBack(eventTarget, eventArgument) { if (!theForm.onsubmit || (theForm.onsubmit() != false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); } } // --> </script> <form id="form1" runat="server"> <header class="mui-bar mui-bar-nav"> <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a> <div style="float: right; width: 25px; height: 25px; padding-top: 10px; margin: 0 5px;"> <a href="index.html"> <img src="images/logo.png" width="100%"></a> </div> <h1 class="mui-title">注册</h1> </header> <div class="mui-content"> <div class="mui-input-group"> <div class="mui-input-row"> <label>真实姓名</label> <input id='truename' runat="server" datatype="s2-4" nullmsg="姓名不能为空!" errormsg="姓名格式错误" type="text" class="mui-input-clear mui-input" placeholder="请输入真实姓名"> </div> <div class="mui-input-row"> <label>身份证号</label> <input id='idno' type="text" runat="server" class="mui-input-clear mui-input" datatype="idcard" nullmsg="请填写身份证号码!" errormsg="您填写的身份证号码不对!" placeholder="请输入身份证号"> </div> <div class="mui-input-row"> <label>手机号</label> <input id='mobile' datatype="m" nullmsg="手机号不能为空" errormsg="手机号错误" runat="server" type="text" class="mui-input-clear mui-input" placeholder="请输入手机号"> </div> <div class="mui-input-row"> <label>验证码:</label> <input id='password' type="text" class="mui-input-clear mui-input" ajaxurl="yxjgHandler.ashx?type=vregsms" placeholder="请输入验证码" datatype="s1-4" nullmsg="验证码不能为空" errormsg="验证码格式不对"> <input type="button" id="btn" class="fsyzm" value="获取验证码" onclick="settimesms(this)" /> </div> <div class="mui-input-row"> <label>密码</label> <input id='password' runat="server" type="password" class="mui-input-clear mui-input" placeholder="请输入密码" datatype="*6-16" nullmsg="请设置密码!" errormsg="密码范围在6~16位之间!"> </div> <div class="mui-input-row"> <label>确认</label> <input id='password_confirm' runat="server" type="password" class="mui-input-clear mui-input" placeholder="请确认密码" datatype="*" recheck="password" nullmsg="请再输入一次密码!" errormsg="您两次输入的账号密码不一致!"> </div> </div> <div class="mui-input-row mui-checkbox mui-left" style="text-align: center;"> <span>我已阅读并同意<a href="license.aspx">《用户协议》</a></span> <input name="checkbox" value="Item 1" type="checkbox" style="left: 5%; margin-top: -3px;" datatype="*" nullmsg="请同意协议!"> </div> <div class="mui-content-padded"> <asp:Button ID="reg" CssClass="mui-btn mui-btn-block mui-btn-primary" runat="server" Text="注册" OnClick="reg_Click" /> </div> <div class="mui-content-padded"> <p>姓名、身份证号、手机号必须真实填写,注册前请认真阅读用户《用户协议》。</p> </div> </div> <script src="js/mui.min.js"></script> </form> </body> </html>
Copyright © 2004-2024 Ynicp.com 版权所有 法律顾问:建纬(昆明)律师事务所 昆明市网翼通科技有限公司 滇ICP备08002592号-4