how to validate files by bootstrap validator?

10,475

You're missing the DOCX mime type :

application/vnd.openxmlformats-officedocument.wordprocessingml.document

So your code should look like :

file: {
      extension: 'doc,docx,pdf,zip,rtf',
      type: 'application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/rtf,application/zip',
      maxSize: 5*1024*1024,   // 5 MB
      message: 'The selected file is not valid, it should be (doc,docx,pdf,zip,rtf) and 5 MB at maximum.'
},

See this fiddle example.

Share:
10,475
MD.MD
Author by

MD.MD

I am a back-end web developer who is in his learning journey, proud to like PHP and open-sources, looking to improve his skills in web development and expanding his knowledge in PHP, Yii framework and JS, in addition to exploring the world of mobile development ASAP.

Updated on June 26, 2022

Comments

  • MD.MD
    MD.MD about 2 years

    I am trying to validate a form with bootstrap validator, but the file validation is not going normal, here is my code:

    cv: {
       validators: {
       file: {
              extension: 'doc,docx,pdf,zip,rtf',
              type: 'application/pdf,application/msword,application/rtf,application/zip',
              maxSize: 5120 * 5120 * 5120 * 5120 * 5120,   // 5 MB
              message: 'The selected file is not valid, it should be (doc,docx,pdf,zip,rtf) and 5 MB at maximum.'
        },
        notEmpty: {
                        message: 'CV is required.'
                  }
        }
      },
    

    the required files extensions are doc,docx,pdf,rtf,zip as shown above, but it only accept 3 extensions: doc,rtf,pdf...so where is the error in my code?