5

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?

Ish
  • 2,085
  • 3
  • 21
  • 38
MD.MD
  • 708
  • 4
  • 14
  • 34

2 Answers2

5

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.

Arkni
  • 1,177
  • 9
  • 15
  • 1
    @user3194430, the zip mime type is correct, you can test it in the fiddle i have created http://jsfiddle.net/Arkni/bm3cukgx/3/ . – Arkni Sep 09 '14 at 12:30
  • @Arkni I added the same logic when I select Docx file getting an error what might be the issue here please tell me. – Husna Oct 01 '19 at 06:05
0

Here is simple example of file filed validation

http://formvalidation.io/validators/file/

Shiplu
  • 460
  • 6
  • 13