判斷上傳文件是否為excel


1. 可以在input上傳組件上添加屬性accept,這樣上傳文件的時候,就只能選擇excel文件了。

<input type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" />  

2.通過正則判斷

if (excel!= '') {
                var reg = /^.*\.(?:xls|xlsx)$/i;//文件名可以帶空格
                if (!reg.test(path)) {//校驗不通過
                    alert("請上傳excel格式的文件!");
                    return;
                }
            }

 

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM