jquery - formvalidation validate only if there is file uploaded -


hi using plugin formvalidation , new this, have form file upload , want check if there file being uploaded , if there validate accept (jpeg,png,gif). , if there none not validate.

<form id="myform">   <div class="form-group">     <label for="fname">first name</label>     <input type="text" class="form-control" id="name" name="fname" placeholder="name">   </div>   <div class="form-group">     <label for="pic">upload here</label>     <input type="file" id="pic">    </div>   <button type="submit" class="btn btn-default">submit</button> </form> 

thank in advance.

you need data-fv-file-type option formvalidator.

the allowed mime type, separated comma. example: setting image/jpeg,image/png,application/pdf allows upload jpeg, png image , pdf document.

use data-fv-file-type="image/jpeg,image/png,application/gif" validate file extensions while uploading.

also, remember enable validator setting data-fv-file="true"

example

<input type="file" class="form-control" name="avatar"             data-fv-file="true"             data-fv-file-extension="jpeg,png"             data-fv-file-type="image/jpeg,image/png"             data-fv-file-maxsize="2097152"             data-fv-file-message="the selected file not valid" /> 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -