文本字段中的jquery验证

时间:2018-06-19 08:26:41

标签: jquery laravel laravel-5 laravel-4 jquery-plugins

当我在google上冲浪时,我得到了插件(jquery form validator),我想进行表单验证,在表单验证中使用插件,它的工作完美但在控制台显示错误,

  

jquery.form-validator.min.js:9未捕获的TypeError:无法读取未定义的属性“length”
      在HTMLDocument.f(jquery.form-validator.min.js:9)
      在HTMLDocument.dispatch(jquery.js:3)
      在HTMLDocument.r.handle(jquery.js:3)
      在Object.trigger(jquery.js:3)
      在m.fn.init.triggerHandler(jquery.js:3)
      在Function.ready(jquery.js:2)
      在HTMLDocument.J(jquery.js:2)

$.validate({
  form: '#form',
  modules: 'location, date, security, file',
});

// Restrict presentation length
$('#presentation').restrictLength($('#pres-max-length'));
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.3.26/jquery.form-validator.min.js"></script>

<div class="form-group col-lg-5">
  {!! Form::label('quantities', 'Traded Quantity:') !!} {!! Form::text('quantities', null, ['class'=>'form-control', 'data-validation'=>'length number', 'data-validation-length'=>'3-12', 'data-validation-error-msg'=>'User name has to be an alphanumeric
  value (3-12 chars)'])!!}
</div>

1 个答案:

答案 0 :(得分:0)

您可以按以下方式对其进行验证:

    $('#form').validate({
       rules: {
        quantities: {
            required: true,
            rangelength: [3, 12],
        },
        other_input_name: "required",
     },
  });