0

I am trying to validate a HTML file upload using jQuery Validate plugin,

My html form is,

<form id="formid" action="welcome/test_up" method="post" enctype="multipart/form-data">
<input type="file" name="myfile[]" id="myfile" multiple>
<input type="submit" name="submit" id="submit" value="submit"/>

And I'm using Jquery validation plugin as,

$('#formid').validate({
    rules: { 
       inputimage: { required: true, accept: "png|jpe?g|gif"  }
    },
    messages: { inputimage: "File must be JPG, GIF or PNG" }
});

But unfortunately it's not working,

It's working if I use name="myfile" but not when I use name="myfile[]"

Any idea to solve this ?

3
  • This may not have anything to do with your JS, but with the actual PHP. Commented May 17, 2014 at 5:20
  • Is there any other way to achieve this ? because i've completed my php scripts with php validation but my client needs some realtime validation. So any idea ? Commented May 17, 2014 at 5:27
  • I'd have to see your PHP. Commented May 17, 2014 at 14:20

1 Answer 1

0

try to set your rule in input tag become

<input type="file" name="myfile[]" id="myfile" accept="png|jpe?g|gif" multiple>

so your js only

$('#formid').validate();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.