Simplest JQuery validation rules example

前端 未结 4 1237
夕颜
夕颜 2020-12-29 09:05

The following HTML form successfully utilizes jQuery\'s form validation, displaying \"This field is required\" to the right of the form field if left blank, and \"Please ent

相关标签:
4条回答
  • 2020-12-29 09:24
    $("#commentForm").validate({
        rules: {
         cname : { required : true, minlength: 2 }
        }
    });
    

    Should be something like that, I've just typed this up in the editor here so might be a syntax error or two, but you should be able to follow the pattern and the documentation

    0 讨论(0)
  • 2020-12-29 09:32
    rules: {
        cname: {
            required: true,
            minlength: 2
        }
    },
    messages: {
        cname: {
            required: "<li>Please enter a name.</li>",
            minlength: "<li>Your name is not long enough.</li>"
        }
    }
    
    0 讨论(0)
  • 2020-12-29 09:35

    The input in the markup is missing "type", the input (text I assume) has the attribute name="name" and ID="cname", the provided code by Ayo calls the input named "cname"* where it should be "name".

    0 讨论(0)
  • 2020-12-29 09:36

    The examples contained in this blog post do the trick.

    0 讨论(0)
提交回复
热议问题