문제

As per my code validation functionality should accept only ZIP version.

So its working on my 1st system all 3 browsers "IE 10, Chrome 29 and Firfox 24" and with NO WINRAR installed

But now I have some strange issue, my code was working fine till the time I didn't have WINRAR installed.On the other system where I have WINRAR installed I am getting issue, that if I upload the ZIP file also, on my second system, still it prompts the error that "It accepts ZIP file only"

Below is my code and the Fiddle too:

JQUERY

<script>

    $().ready(function () {

        // validate signup form on keyup and submit
        $("#deploymentUploadForm").validate({

            rules:{
                File: {
                    required: true,
                    accept: "application/zip,application/octet-stream,application/x-zip,application/x-zip-compressed"
                }
            },

            messages:{
                File: {
                    required: "This field is mandatory!",
                    accept: "Accepts only zip file!"
                }
            }  

        });

    });
</script>

HTML

    <div id="wizardSteps">
            <form action="~/Deployment/FileUpload" name="deploymentUploadForm" id="deploymentUploadForm" enctype="multipart/form-data" method="post">
                <h1>Deployment</h1>

                <p>
                    <input type="file" name="File" accept="application/zip">
                </p>

                <div role="button" class="marginTop50 marginBottom">
                    <p>
                        <input type="submit" id="getDeploymentList" value="Upload" class="active" >
                    </p>
                </div>
            </form>
        </div>

Fiddle http://jsfiddle.net/aasthatuteja/rMS8D/

I am getting the same issue fiddle too when I installed WINRAR in my 1st system (which was working fine beforer installing the WINRAR)

Please let me know if you need anything else.

Thanks in adavance!

도움이 되었습니까?

해결책

After struggling alot to find why the "accept:" method is not accepting zip file which is created by "WinRaR".. I changed the "accept" method with "extension" which is provided in "additional-methods.js" -- <script src="http://jquery.bassistance.de/validate/additional-methods.js"></script>. Please find the latest code below:

JQUERY:

<script>

    $().ready(function () {

        // validate signup form on keyup and submit
        $("#deploymentUploadForm").validate({

            rules:{
                File: {
                    required: true,
                    extension: "zip"
                }
            },

            messages:{
                File: {
                    required: "This field is mandatory!",
                    extension: "Accepts only zip file!"
                }
            }  

        });

    });
</script>

If you don't want to include the full "additional-methods.js" then below is the method:-

jQuery.validator.addMethod("extension", function(value, element, param) {
  param = typeof param === "string" ? param.replace(/,/g, '|') : "png|jpe?g|gif";
  return this.optional(element) || value.match(new RegExp(".(" + param + ")$", "i"));
}, jQuery.format("Please enter a value with a valid extension."));

Thanks all for looking into the issue!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top