js通过正则表达式,判断文件类型
作者:互联网
getFileType (url) {
let pdfReg = /^.+(\.pdf)$/
let txtReg = /^.+(\.txt)$/
let wordReg = /^.+(\.doc|\.docx)$/
let excelReg = /^.+(\.xls|\.xlsx)$/
let jpgReg = /^.+(\.png|\.jpg|\.jpeg|\.bmp)$/
if (pdfReg.test(url)) {
return 'pdf'
}
if (txtReg.test(url)) {
return 'txt'
}
if (wordReg.test(url)) {
return 'word'
}
if (excelReg.test(url)) {
return 'excel'
}
if (jpgReg.test(url)) {
return 'picture'
}
}
标签:.+,return,正则表达式,js,url,let,test,文件类型,txt 来源: https://www.cnblogs.com/thomas-tang/p/15232258.html