zoukankan      html  css  js  c++  java
  • jquery validate minlength rule is not working

    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: 8
                }
            }
        });

    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: 8
            }
        }
    });

    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

  • 相关阅读:
    2013.11.19上班 任务:写文档
    js 时间比较和货币格式显示
    SQL优化
    多线程消费队列中的接口数据,接口数据来源是kafka
    List<Map<String, Object>> 中根据某一个属性进行排序
    ES查询操作
    Valid Sudoku
    Decode Ways
    Jump Game
    Best Time to Buy and Sell Stock II
  • 原文地址:https://www.cnblogs.com/pinganzi/p/6244570.html
Copyright © 2011-2022 走看看