admin管理员组文章数量:1295257
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
2 Answers
Reset to default 9var 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
本文标签: Javascriptregex to validate document filesPDFtxtdocStack Overflow
版权声明:本文标题:Javascript - regex to validate document files - PDF, TXT, DOC - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741612408a2388335.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论