Home > Web Front-end > JS Tutorial > JavaScript verifies that the type restriction of uploaded files must be in certain formats_javascript tips

JavaScript verifies that the type restriction of uploaded files must be in certain formats_javascript tips

WBOY
Release: 2016-05-16 17:15:09
Original
1336 people have browsed it
Copy code The code is as follows:

//Verify the format of the file
function validateFile(){
var fileObject=$("#filename");
var errorObject=$("#error");
var filepath=fileObject.val();
var fileArr=filepath.split(" //");
var fileTArr=fileArr[fileArr.length-1].toLowerCase().split(".");
var filetype=fileTArr[fileTArr.length-1];
if (filetype!="xls"&&filetype!="xlsx"&&filetype!="doc"&&filetype!="docx"
&&filetype!="jpeg"&&filetype!="jpg"&&filetype!="ppt"&&filetype!=" pptx"
&&filetype!="txt"&&filetype!="bmp"&&filetype!="png"&&filetype!="gif"){
fileObject.focus();
errorObject.html("Upload file Must be a picture, doc, ppt, xls, txt file! ");
}else{
errorObject.remove();
}
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template