Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript - regex to validate document files - PDF, TXT, DOC

I'm using blueimp File Upload plugin to upload files. There's an example regex to restrict the upload to images only:

var acceptFileTypes = /^image\/(gif|jpe?g|png)$/i;

How can I change this to upload image files, and documents like PDF, TXT, DOC?

like image 981
user1049961 Avatar asked Apr 29 '26 03:04

user1049961


1 Answers

var acceptFileTypes =
/^image\/(gif|jpe?g|png)$|^application\/(pdf|msword)$|^text\/plain$/i;

This seems to assume that the correct mime type is checked against acceptFileTypes

like image 144
Explosion Pills Avatar answered May 01 '26 16:05

Explosion Pills