jQuery验证表单不是验证和提交

时间:2015-04-26 15:07:21

标签: javascript jquery forms validation form-submit

我已正确设置所有规则,但在提交表单时似乎完全忽略了它们。

这是我的代码:



#include <cmath>
&#13;
$(document).ready(function() {

  $('#formValidation').validate({
    rules: {
      name: {
        required: true,
        minlength: 2,
        lettersonly: true,
      },
      email: {
        required: true,
        minlength: 5,
        email: true,
      },
      feedback: {
        required: true,
        minWords: 5,
      },
    }
    messages: {
      name: {
        required: "Please enter your name",
      },
    },
  });
});
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

所以,您只需要以下内容。

$(document).ready(function () {

    $('#formValidation').validate({ 
        rules: {
            name: {
                required: true,
                minlength: 2,
                lettersonly:true,
            },
            email: {
                required: true,
                minlength: 5,
                email:true,
            },
            feedback: {
                required: true,
                minWords: 5,
            }
        },
        messages: {
            name:{
                required:"Please enter your name",
            }
        }
    });  
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://jqueryvalidation.org/files/dist/jquery.validate.js"></script>
<form id="formValidation" method="post">
    <p>Name: <br/><input type="text" name="name" /> </p>
    <p>Email:<br/><input type="email" name="email" /></p>
    <p>Feedback:<br/><input type="text" name="feedback" id="textfield"/>
    <input type="submit" id="submit"/> </p>
</form>

  • 从您的脚本中删除了不必要的/额外的,
  • 删除内联事件处理程序