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

I'm using blueimp File Upload plugin to upload files. There's an example regex to restrict th

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?

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?

Share Improve this question asked Apr 7, 2014 at 18:53 user1049961user1049961 2,7369 gold badges40 silver badges69 bronze badges 1
  • 3 Is it not working now? If so, what errors/unexpected results? If it is working and you just want to add extensions, just add it to the group of ORs ([..]png|pdf|txt|doc)$). – Sam Commented Apr 7, 2014 at 18:55
Add a ment  | 

2 Answers 2

Reset to default 9
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

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

and make sure that these files are kept inside the image folder. so the full path to the text file should be something like /image/dsds/file.txt

if you want to add your own folder name it accordingly

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1741612408a4356531.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信