jQuery Plugins Validate

validate报错

 1 //onfocusout默认为true,但是加上会报错。
 2 //官方文档解释:
 3 //A boolean true is not a valid value.
 4 $("#test").validate({
 5     debug:true,
 6     onfocusout:true,
 7     rules: {
 8         testName: "required",
 9     },
10     messages: {
11         testName: { required: "请输入姓名" }
12     }
13 });

校验规则写在js代码

表单元素的获取使用name属性,区分大小写

 1 $().ready(function () {
 2     $("#formRegister").validate({
 3         debug: true,
 4         rules: {
 5             Email: {
 6                 required: true,
 7                 email: true,
 8             },
 9             Password: {
10                 required: true,
11                 rangelength: [6, 20],
12             },
13             repeat: {
14                 equalTo: ‘#password‘,
15             }
16         },
17         messages: {
18             Email: {
19                 required: ‘Email必须填写‘,
20                 email: ‘请输入正确的Email地址‘,
21             },
22             Password: {
23                 required: ‘密码必须填写‘,
24                 rangelength: ‘密码长度6-20位‘,
25             },
26             repeat: {
27                 equalTo: ‘两次输入的密码必须相同‘
28             }
29         }
30     });
31 });

校验代码写在html控件

 1 <form id="myform" method="post" action="">
 2     <p>
 3         <label for="myname">用户名:</label>
 4         <!-- id和name最好同时写上 -->
 5         <input id="myname" name="myname" class="required" />
 6     </p>
 7     <p>
 8         <label for="email">E-Mail:</label>
 9         <input id="email" name="email" class="required email" />
10     </p>
11     <p>
12         <label for="password">登陆密码:</label>
13         <input id="password" name="password" type="password"
14                class="{required:true,minlength:5}" />
15     </p>
16     <p>
17         <label for="confirm_password">确认密码:</label>
18         <input id="confirm_password" name="confirm_password" type="password"
19                class="{required:true,minlength:5,equalTo:‘#password‘}" />
20     </p>
21     <p>
22         <label for="confirm_password">性别:</label>
23         <!-- 表示必须选中一个 -->
24         <input type="radio" id="gender_male" value="m" name="gender" class="{required:true}" />
25         <input type="radio" id="gender_female" value="f" name="gender" />
26     </p>
27     <p>
28         <label for="confirm_password">爱好:</label>
29         <!-- checkbox的minlength表示必须选中的最小个数,maxlength表示最大的选中个数,rangelength:[2,3]表示选中个数区间  -->
30         <input type="checkbox" id="spam_email" value="email" name="spam[]" class="{required:true, minlength:2}" />
31         <input type="checkbox" id="spam_phone" value="phone" name="spam[]" />
32         <input type="checkbox" id="spam_mail" value="mail" name="spam[]" />
33     </p>
34     <p>
35         <label for="confirm_password">城市:</label>
36         <select id="jungle" name="jungle" title="Please select something!" class="{required:true}">
37             <option value=""></option>
38             <option value="1">厦门</option>
39             <option value="2">泉州</option>
40             <option value="3">Oi</option>
41         </select>
42     </p>
43     <p>
44         <input class="submit" type="submit" value="立即注册" />
45     </p>
46 </form>
时间: 2024-08-24 23:11:17

jQuery Plugins Validate的相关文章

jquery插件-validate

1.引入js,css 下载地址:http://plugins.jquery.com/validate/ 2.设置验证规则:input的class添加以下属性 3.设置不符合规则的提示信息:添加data-msg-xxx(xxx为以下属性)               required: "必选字段",         remote: "请修正该字段",         email: "请输入正确格式的电子邮件",         url: &quo

JQuery插件validate的Remote使用

JQuery.validate.js 在表单验证中经常使用,初学,对于其中Remote的使用说明一下. 1. 基本解释 JQuery主要用于DOM树和CSS树的检索和后面的操作的一套方法,JQuery.validate.js是对JQuery的一个插件,可以认为是对JQuery在某个特殊场景下的扩展,而Validate就是对表单验证提供的扩展. 2. 场景解释 用户进行注册用户的时候,要异步的判断用户名是否存在,给出提示信息. 3. 通过案例学习 Html和JavaScript结合的脚本. 1 <

jquery的validate的用法

//引入js文件 //jquery 文件 <script src="__PUBLIC__/static/wap/js/jquery.min.js?v=2.1.4"></script> //jquery 的表单提交插件<script src="__PUBLIC__/static/wap/js/jquery.form.js"></script> //验证js类<script src="__PUBLIC__/

Writing Your Own jQuery Plugins

Setting Up 1 <script src="js/jquery-1.9.1.min.js"></script> 2 <script src="js/jquery.hello-world.js"></script> The jQuery Plugin Structure 1 (function($) { 2 3 $.fn.helloWorld = function() { 4 5 // Future home o

jquery 之validate 笔记

默认分类 2010-04-04 20:35:01 阅读123 评论0 字号:大中小 jquery.validate是jquery旗下的一个验证框架,借助jquery的优势,我们可以迅速验证一些常见的输入,并且可以自己扩充自己的验证方法,并且对国际化也有很好的支持.说明:需要JQuery版本:1.2.6+步骤:1, 要导入相应的jQuery.js与jquery.validate.js文件<script src="jquery.js" type="text/javascri

基于jQuery的Validate表单验证

表单验证可以说在前端开发工作中是无处不在的~ 有数据,有登录,有表单, 都需要前端验证~~  而我工作中用到最多的就是基于基于jQuery的Validate表单验证~  就向下面这样~ 因为今天有个朋友问我要一个表单的验证,所以我就稍微整理了一下~  基本上有了这个表单验证插件,基本上一些常用的验证都可以搞定了~ 如果搞不定,没关系,我们还可以基于Validate来写一个自己的验证插件, 我把它取名为message_zh.js,我们可以在里面扩展自己需要的验证~~ 既然Validate是基于jQ

JQuery 【validate】缓存

[第一次] 与 [第二次] 检验值相同时,强制再次进行校验~ if($.data(document.getElementById("userName"), "previousValue")) { $.data(document.getElementById("userName"), "previousValue").old = null; } JQuery [validate]缓存

jQuery的validate验证插件使用方法

(1)默认校验规则(1)required:true 必输字段(2)remote:"check.php" 使用ajax方法调用check.php验证输入值(3)email:true 必须输入正确格式的电子邮件(4)url:true 必须输入正确格式的网址(5)date:true 必须输入正确格式的日期(6)dateISO:true 必须输入正确格式的日期(ISO),例如:2009-06-23,1998/01/22 只验证格式,不验证有效性(7)number:true 必须输入合法的数字(

Jquery Plugins Jquery Validate

  Jquery Validate 一.什么是Jquery Validate: jQuery Validate 插件为表单提供了强大的验证功能. 二.常用值: 1 required:true 必须输入的字段. 2 remote:"check.php" 使用 ajax 方法调用 check.php 验证输入值. 3 email:true 必须输入正确格式的电子邮件. 4 url:true 必须输入正确格式的网址. 5 date:true 必须输入正确格式的日期.日期校验 ie6 出错,慎