//实名认证 验证
$(function(){ //中文姓名验证
jQuery.validator.addMethod("zh_verify", function(value, element) {
var tel = /^[\u4E00-\u9FA5\uf900-\ufa2d]{2,10}$/;
return this.optional(element) || (tel.test(value));
}, "请输入2~10个字的中文!"); //身份证号验证
jQuery.validator.addMethod("idcard_verify", function(value, element) {
var idcard = /^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/;
return this.optional(element) || (idcard.test(value));
}, "请输入正确格式的身份证号!"); //jquery.validate插件验证
$("#nameauth").validate({
errorElement: 'div',
errorClass: 'help-block',
focusInvalid: false,
ignore: "",
rules: {
tname: {
required: true,
zh_verify:true
},
idcard: {
required: true,
idcard_verify:true
},
con_idcard: {
required: true,
equalTo: '.idcard'
}
},
messages: {
tname: {
required: "真实姓名不能为空!",
rangelength: "请输入2~18个中文!"
},
idcard: {
required: "身份证不能为空!",
rangelength: "请输入15~18个字符的身份证!"
},
con_idcard: {
required: "确认证号不能为空!",
equalTo: '确认证号与身份证号不一致!'
}
},
errorLabelContainer: "#resultMsg",
submitHandler:function() {
//$(form).ajaxSubmit(); //同步提交FORM
var tname = $('input[name=tname]').val();
var idcard = $('input[name=idcard]').val();
var resultMsg = $('#resultMsg');
ajaxSubmitForm(tname, idcard, resultMsg);
}
});
}) //异步执行方法
function ajaxSubmitForm(tname, idcard, resultMsg) {
$.ajax({
url: "/member/nameauth",
data: "tname=" + tname + "&idcard=" + idcard + "&con_idcard=" + idcard,
type: "post",
cache: false,
dataType: "json",
success: function(data, textStatus){
if(data.return){
window.location.reload();
}else{
resultMsg.css({'color': 'red'}).html(data.errmsg).show().delay(2000).hide(0);
}
}
});
}

或者

$(function(){
//jquery.validate插件自定义AJAX验证(验证账户是否存在)
$.validator.addMethod("checkUserExist",function(value,element){
var user = value;
$.ajax({
type:"POST",
async:true,
dataType:'json',
url:"/account/verifyAccount",
data:"param=" + $('input[name=newpassword]').val(),
success:function(response){
if(response){
res = response.state;
}
}
});
return res;
},"账号不存在,请仔细检查!"); //jquery.validate插件验证
$("#signupForm").validate({
rules: {
newpassword: {
required: true,
rangelength:[6,30]
}
},
messages: {
newpassword: {
required: "请输入6~30个字符的交易密码!",
rangelength: "请输入6~30个字符的交易密码!"
}
},
submitHandler:function(form) {
$(form).ajaxSubmit();
}
});
})

jQuery Validate教程

http://www.w3cschool.cc/jquery/jquery-plugin-validate.html

jQuery Validate验证方法及教程的更多相关文章

  1. 修改jQuery.validate验证方法和提示信息

    1.添加验证方法 在jquery.validate.js文件中直接添加验证方法,例如: jQuery.validator.addMethod("Specialstring", fu ...

  2. jquery validate验证方法

    实例: equalTo方法 equalTo(其他)返回:布尔 说明:要求元素与另一个元素相同 等于(其他) 其他 类型:选择器 元素的选择器用于比较当前值 例子: 使“字段”必须与#other相同 1 ...

  3. jQuery.Validate 验证,以及 remote验证, 多参数传递

    jQuery.Validate 验证: http://www.runoob.com/jquery/jquery-plugin-validate.html 教程网址,很简单, 今天主要在这里记录一下re ...

  4. jQuery Validate验证框架详解

    转自:http://www.cnblogs.com/linjiqin/p/3431835.html jQuery校验官网地址:http://bassistance.de/jquery-plugins/ ...

  5. jquery.validate 验证机制

    jquery.validate 验证机制 金刚 juqery juqery.validate 在开发系统时,使用了jquery.validate.js 这个验证插件,来校验数据合法性 重点 验证是以i ...

  6. 弹出框页面中使用jquery.validate验证控件

    弹出框页面中使用jquery.validate验证控件有几个问题需要解决: 1,弹出框的提交事件完成后如何关闭弹出框页面? 2,提交不成功如何返回当前页? 3,如果知道验证事件成功? 之前笔者都是JS ...

  7. 【转】jQuery Validate验证框架详解

    jQuery校验官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation 一.导入js库 <script type=& ...

  8. jQuery Validate验证框架与 jQuery ajaxSubmit的联合使用

    jQuery Validate验证框架自定义验证 第一步导入导入js库 <script src="<%=basePath%>static/js/jquery.js" ...

  9. atitit.jQuery Validate验证框架详解与ati Validate 设计新特性

    atitit.jQuery Validate验证框架详解与ati Validate 设计新特性 1. AtiValidate的目标1 2. 默的认校验规则1 2.1. 使用方式 1.metadata用 ...

随机推荐

  1. angular之service、factory预provider区别

    昨晚项目组做了angular分享,刚好有讨论到这个问题.虽然许久不做前端开发,但是兴趣所致.就查阅了下资料,以便后续需要使用 自己的理解:service是new出来的,factory是直接使用就能获得 ...

  2. Aborted connection 1055898 to db: 'xxx' user: 'yyy' host: 'xxx.xxx.xxx.xxx' (Got timeout reading communication packets)

    mysql错误日志中,发现大量以下类似信息:(mysql 5.7.18) [Note] Aborted connection 1055898 to db: 'xxx' user: 'yyy' host ...

  3. cors的实现原理

    如何辨认一个请求的源domain? 如何发送和处理cors请求? 优势 和 弱点 cookie 和 伪装 1. http://www.staticapps.org/articles/cross-dom ...

  4. Groovy 学习手册(3)

    五. Groovy 的设计模式 设计模式是一种非常好的方式,可以使你的代码变得实用,可读又具有扩展性.跟 Java 相比,在 Groovy 里使用设计模式使代码更加简洁和容易. 1. 策略模式 设想一 ...

  5. apache apr的编译和引用

    各种巧合吧,需要从JAVA转C,经过这一段时间的心理折磨,还是决定先把精力放到C上. 想快速的提高自己,学习相关语言的经典的源码是唯一的“捷径”,从Apache apr开始吧. 一.下载源代码 官网地 ...

  6. jms异步转同步调用实例

    思路: 当主线程调用异步方法时,将自己挂起,并把引用交给jms的监听: 当监听收到返回的消息时,处理并唤醒主线程继续执行(可以获取和处理返回的消息) Test.java package com.my. ...

  7. 验证码识别 图像降噪 Python (一)

    原始图片: 降噪后的图片 实现代码: # coding:utf-8 import sys, os from PIL import Image, ImageDraw # 二值数组 t2val = {} ...

  8. Java实现打印功能

    用java实现打印,java.awt中提供了一些打印的API,要实现打印,首先要获得打印对象,然后继承Printable实现接口方法print,以便打印机进行打印,最后用Graphics2D直接输出直 ...

  9. Vivado抓取信号

    作者:桂. 时间:2018-05-03  21:16:03 链接:www.cnblogs.com/xingshansi/p/8987608.html 前言 FPGA调试需要抓取特定信号,一个直观的思路 ...

  10. unity, dll is not allowed to be included or could not be found

    player settings change to Net 2.0 ref: http://answers.unity3d.com/questions/485085/dll-is-not-allowe ...