Question:

I have a form with a password field. The password has to be at least 8 characters long.

<form action="/account/register" method="post" id="form-register">
<div class="input-row">
<input name="data[User][password]" type="password" id="FUserPassword" class="required" placeholder="Password">
</div> </form> $("#form-register").validate({
rules: {
FUserPassword : {
minlength:
}
}
});

It applies the "required" rule, but it just ignores the "minlength" rule.

What am I doing wrong? I'm using the same code (the JS part) on other pages and it works as expected.

Answer:

Validate looks for the name of the input field, not the id. From the documentation for the rulesoption:

Key/value pairs defining custom rules. Key is the name of an element (or a group of checkboxes/radio buttons)

With that in mind, you should use something like this:

$("#form-register").validate({
rules: {
'data[User][password]': {
minlength:
}
}
});

For input names with special characters, be sure to quote the object key.

转自: http://stackoverflow.com/questions/14404884/jquery-validate-minlength-rule-is-not-working

jquery validate minlength rule is not working的更多相关文章

  1. ligerui的jquery.validate验证需要添加validate="{required:true,minlength:8,equalTo:'#newpassword'}"

    ligerui的jquery.validate验证需要添加validate="{required:true,minlength:8,equalTo:'#newpassword'}"

  2. jQuery.validate errorPlacement

    在被验证的控件的后一个元素控制显示 errorPlacement: function(error, element) { element.next().css("color",&q ...

  3. Jquery validate验证表单时多个name相同的元素只验证第一个的问题

    下面搜集了五种方法,主要还是前两个提供了解决方案,第三种需要修改jQuery源码: 修复jquery.validate插件中name属性相同(如name='a[]')时验证的bug 使用jquery. ...

  4. jQuery Validate 表单验证 — 用户注册简单应用

    相信很多coder在表单验证这块都是自己写验证规则的,今天我们用jQuery Validate这款前端验证利器来写一个简单的应用. 可以先把我写的这个小demo运行试下,先睹为快.猛戳链接--> ...

  5. jquery validate表单验证插件-推荐

    1 表单验证的准备工作 在开启长篇大论之前,首先将表单验证的效果展示给大家.     1.点击表单项,显示帮助提示 2.鼠标离开表单项时,开始校验元素  3.鼠标离开后的正确.错误提示及鼠标移入时的帮 ...

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

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

  7. jQuery Validate验证框架详解

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

  8. JS验证控件jQuery Validate

    jQuery Validate 插件为表单提供了强大的验证功能,让客户端表单验证变得更简单,同时提供了大量的定制选项,满足应用程序各种需求.该插件捆绑了一套有用的验证方法,包括 URL 和电子邮件验证 ...

  9. jquery:validate的例子

    该文档转载自 http://ideabean.javaeye.com/blog/363927 官方网站 http://bassistance.de/jquery-plugins/jquery-plug ...

随机推荐

  1. nginx 虚拟主机配置

    user nginx; #代表使用的用户 worker_processes auto; #工作衍生进程数,一般代表系统cpu核数一到两倍最好 error_log /var/log/nginx/erro ...

  2. FragmentTabHost简单保存状态的方法

    private View rootView;@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container ...

  3. xss篇-本着就了解安全本质的想法,尽可能的用通俗易懂的语言去解释安全漏洞问题

    前言 最早接触安全也是从xss攻击和sql注入攻击开始的. 0x01    跨站脚本攻击漏洞(XSS),是客户端脚本安全中的头号大敌,owasp top10 屡居榜首,由于攻击手法较多,开发者水平不一 ...

  4. 【BZOJ 1016】【JSOI 2008】最小生成树计数

    http://www.lydsy.com/JudgeOnline/problem.php?id=1016 统计每一个边权在最小生成树中使用的次数,这个次数在任何一个最小生成树中都是固定的(归纳证明). ...

  5. Block常用方法以及注意事项

    1. ViewController间传递数据 2. Block的@property必须定义为copy

  6. 基于Visual Studio Code搭建Golang开发调试环境【非转载】

    由于对Docker+kubernetes的使用及持续关注,要理解这个平台的原理,势必需要对golang有一定的理解,基于此开始利用业余时间学习go,基础语法看完之后,搭建开发环境肯定是第一步,虽然能g ...

  7. sublime text3 使用SVN插件

    Simon在项目中经常使用SVN,每次都要切换提交,很麻烦,有了这个SVN插件就很方便了,使用快捷方式提交,更新. 安装: Ctrl + Shift + P 调用出Sublime Text的包管理工具 ...

  8. 理解Compressed Sparse Column Format (CSC)

    最近在看<Spark for Data Science>这本书,阅读到<Machine Learning>这一节的时候被稀疏矩阵的存储格式CSC给弄的晕头转向的.所以专门写一篇 ...

  9. 前端之DIV+CSS布局

    刚开始学习javaweb,首先定位学习后端,可是随着学习的深入和项目的进行,越来越发现前端知识的欠缺,之前也随着视频看过,随着时间的流逝,具体的应用也随之忘记了. 而现在开始自己练习项目,发现前端知识 ...

  10. php-7.1.0 rpm包制作

    nginx-1.8.0 rpm包制作见上篇文章:http://www.cnblogs.com/xiaoming279/p/6251149.html spec文件 Name: php Version: ...