How to validate upload file by Bootstrap

How to validate upload file by Bootstrap validation as an image type(png,jpg) or file (pdf,zip) etc 

<form id="uploadFile" name="uploadFile" enctype="multipart/form-data">
<div class="col-md-4">
      <input type="file" class="" name="fileUpload" id="fileUpload"/>           
 </div>
<button type="submit" name="submitButton" class="btn btn-primary btn-block">Register</button>
</form>

 

Solution..

<script>
$(document).ready(function() {
$('#uploadFile').bootstrapValidator({
    fields: {     
                fileUpload: {
                    validators: {
                        notEmpty: {
                            message: 'File is required and can\'t be empty'
                        },
                        file: {
                            extension: 'doc,docx,pdf,zip,rtf,jpeg,jpg,png',
                            type: 'application/pdf,application/msword,application/vnd.openxmlformats-                                officedocument.wordprocessingml.document,application/rtf,application/zip,jpeg,jpg,png',
                            maxSize:  20*1024*1024,   // 20 MB
                            message: 'The selected file is not valid'
                        },
                    }
                }
        }
    })
    });
</script>

Related Articles

post a comment