<script>
$(function(){
$("#myform").validate(
{ rules: {
name:{required:true,rangelength:[6,20],
remote:{ //验证用户名是否存在
type:"POST",
url:"loginVerifyAction", //servlet
data:{
name:function(){return $("#name").val();}
}
}
},
password: {required:true,minlength:6},
repassword: {required:true,equalTo:"#password"},
veryCode: {required:true,
remote:{
type:"POST",
url:"valCodeAction",
data:{
veryCode:function(){return $("#veryCode").val();}
}
}
}
},
messages: {
name:{required:"用户名不能为空!",rangelength:jQuery.format("用户名位数必须在{0}到{1}字符之间!"),remote:jQuery.format("用户名已经被注册")},
password: {required:"密码不能为空!",minlength:jQuery.format("密码位数必须大于等于6个字符!")},
repassword: {required:"确认密码不能为空!",equalTo:"确认密码和密码不一致!"},
veryCode: {required:"请输入验证码",remote:jQuery.format("验证码错误")}
}
});
}); </script> servlet代码: //验证用户名是否存在 public class LoginVerifyAction extends HttpServlet {
public void service(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException { response.reset();
response.setContentType("text/html;charset=UTF-8");
//业务逻辑操作countByParams得到值并存储到num中
if(num!=0){
response.getWriter().print(false);
}
else{
response.getWriter().print(true);
}
}
} //验证验证码 public class ValCodeAction extends HttpServlet { public void service(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
//得到验证码的操作请看另一篇文章 :验证码
response.setContentType("text/html;charset=UTF-8");
String validateC = request.getSession().getAttribute("validateCode").toString().trim();
String veryCode = request.getParameter("veryCode").trim();
if(veryCode.equals(validateC)){
response.getWriter().print(true);
}else{
response.getWriter().print(false);
}
} xml中的配置 : 忽略。。。

jquery.validate.js的remote用法的更多相关文章

  1. (转)jquery.validate.js 的 remote 后台验证

    之前已经有一篇关于jquery.validate.js验证的文章,还不太理解的可以先看看:jQuery Validate 表单验证(这篇文章只是介绍了一下如何实现前台验证,并没有涉及后台验证remot ...

  2. jquery.validate.js 表单验证简单用法

    引入jquery.validate.js插件以及Jquery,在最后加上这个插件的方法名来引用.$('form').validate(); <!DOCTYPE html PUBLIC " ...

  3. jquery validate.js表单验证的基本用法入门

    这里转载一篇前辈写的文章,在我自己的理解上修改了一下,仅作记录. 先贴一个国内某大公司的代码: 复制代码 代码如下: <script type="text/javascript&quo ...

  4. jquery.validate.js remote (php)

    网上的人不厚道呀 validate 这玩意的异步是 返回的 echo 'true'  或者 echo 'false';很少有人说呀~.~  转载了一篇原文: jquery.validate.js对于数 ...

  5. jquery.validate.js表单验证 jquery.validate.js的用法

    jquery.validate.js这个插件已经用了2年多了,是一个不可多得的表单验证最方便快捷的插件.基于jquery的小插件,基本小白一学就会上手,对于项目表单页面比较多,元素比较多的校验,该插件 ...

  6. jquery.validate.js使用说明——后台添加用户邮箱功能:非空、不能重复、格式正确

    重点内容为:  jQuery验证控件jquery.validate.js使用说明+中文API[http://www.tuicool.com/articles/iABvI3] 简单教程可以参考[jQue ...

  7. 表单验证插件之jquery.validate.js

    提到表单验证的插件,第一个想到的就是jquery.validate.js,所以小生想在这里稍微详细地说一下这款插件的具体使用方法,便于理解,我直接附上整段demo的代码(没怎么调样式,主要是看js): ...

  8. jQuery验证控件jquery.validate.js使用说明

    官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation jQuery plugin: Validation 使用说明 转载 ...

  9. jquery.validate.js插件使用

    jQuery验证控件jquery.validate.js使用说明+中文API 官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-valid ...

随机推荐

  1. [Effective JavaScript 笔记]第31条:使用Object.getPrototypeOf函数而不要使用__proto__属性

    ES5引入Object.getPrototypeOf函数作为获取对象原型的标准API,但由于之前的很多js引擎使用了一个特殊的__proto__属性来达到相同的目的.但有些浏览器并不支持这个__pro ...

  2. 写时复制技术(Copy-on-write)

    COW技术初窥:        在Linux程序中,fork()会产生一个和父进程完全相同的子进程,但子进程在此后多会exec系统调用,出于效率考虑,linux中引入了"写时复制" ...

  3. 算法训练 Torry的困惑

    问题描述 Torry从小喜爱数学.一天,老师告诉他,像2.3.5.7……这样的数叫做质数.Torry突然想到一个问题,前10.100.1000.10000……个质数的乘积是多少呢?他把这个问题告诉老师 ...

  4. Count Numbers with Unique Digits

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

  5. Best Time to Buy and Sell Stock | & || & III

    Best Time to Buy and Sell Stock I Say you have an array for which the ith element is the price of a ...

  6. poj 2709

    http://poj.org/problem?id=2709 题意:就是那个老师需要n瓶颜色的墨水,和1瓶颜色的灰色的墨水,但是灰色的墨水没得卖,只能由三种颜色相同的墨水混合而成,但是3瓶50ML的墨 ...

  7. tesseract3.02识别验证码需要注意的问题

    1.安装tesseract3.02后,在命令行里输入tesseract,看能否出现使用方法,不出现则是环境变量问题,可调整其顺序. 2.找到如下文件 C:\Python27\Lib\site-pack ...

  8. scp失效问题

    1.症状 (1)登陆到服务器A(已在本机用ssh-add, ssh -A),scp 到服务器B时提示public key有问题: (2)/tmp/下没有ssh-XXX目录 2.原因 服务器A被pupp ...

  9. 使用kettle转换中的JavaScript对密码进行加密和解密

    日常开发中,为了确保账号和密码的安全,时常要对密码进行加密和解密.然而kettle是怎么对密码进行加密和解密的呢? 下面的代码需要再转换中的JavaScript中运行. var encrypted_p ...

  10. Java中必须了解的常用类

    1.Java的包装类 基本数据类型我们都很熟悉,例如:int.float.double.boolean.char等,基本数据类型不具备对象的特征,不能调用方法,一般能实现的功能比较简单,为了让基本数据 ...