用于类型文件和其他验证的jQuery Form Validator无效

时间:2017-03-15 11:46:18

标签: javascript jquery file validation jquery-form-validator

我使用了带有jquery表单验证器的asp.net mvc。

我在类型文件html上应用了jquery表单验证器。

当用户上传超过规定尺寸的文件时,我必须停止提交?

请查看此fiddle

在小提琴中它工作正常,但在我的代码中它没有按预期工作。

我的代码:

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.3.26/jquery.form-validator.min.js"></script>

    <h2>FileUpload</h2>

    <form action="~/home/FileUpload" id="registration-form" enctype="multipart/form-data">
        <p>
            E-mail
            <input name="email" data-validation="email">
        </p>
        <p>
            User name
            <input name="user" data-validation="length alphanumeric"
                   data-validation-length="3-12"
                   data-validation-error-msg="User name has to be an alphanumeric value (3-12 chars)">
        </p>
        <p>
            Password
            <input name="pass_confirmation" data-validation="strength"
                   data-validation-strength="2">
        </p>
        <p>
            Repeat password
            <input name="pass" data-validation="confirmation">
        </p>
        <p>
            Birth date
            <input name="birth" data-validation="birthdate"
                   data-validation-help="yyyy-mm-dd">
        </p>
        <p>
            Country
            <input name="country" id="country" data-validation="country">
        </p>
        <p>
            Profile image
            <input name="image" type="file" data-validation="mime size required"
                   data-validation-allowing="jpg, png"
                   data-validation-max-size="100kb"
                   data-validation-error-msg-required="No image selected">
        </p>
        <p>
            User Presentation (<span id="pres-max-length">100</span> characters left)
            <textarea name="presentation" id="presentation"></textarea>
        </p>
        <p>
            <input type="checkbox" data-validation="required"
                   data-validation-error-msg="You have to agree to our terms">
            I agree to the <a href="..." target="_blank">terms of service</a>
        </p>
        <p>
            <input type="submit" value="Validate">
            <input type="reset" value="Reset form">
        </p>
    </form>

    <script>

       $.validate({
    modules : 'location, date, security, file',
    onModulesLoaded : function() {
      $('#country').suggestCountry();
    }
  });

  // Restrict presentation length
  $('#presentation').restrictLength( $('#pres-max-length') );
    </script>

没有提交验证火没有显示错误。它在我的应用程序中提交表单时没有错误。

DOWNLOAD CODE

0 个答案:

没有答案