accept only pdf input file code example

Example 1: input type file allow only pdf

<input type="file" id="test" name="test" accept=".pdf,.doc"/>

Example 2: how to ensure only pdf files are selected

<input type="file" name="upload" accept="application/pdf,application/vnd.ms-excel" />

Example 3:

<input name="userfile" type="file" accept="application/pdf, application/vnd.ms-excel" />

Example 4: input type=file'' accept only doc and pdf

<input #fileInput type="file" id="avatar" accept="application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document" />

application/pdf means .pdf
application/msword means .doc
application/vnd.openxmlformats-officedocument.wordprocessingml.document means .docx

Example 5: input type=file'' accept only doc and pdf

application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.ms-powerpoint, application/vnd.openxmlformats-officedocument.presentationml.slideshow, application/vnd.openxmlformats-officedocument.presentationml.presentation

Tags:

Misc Example