最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论