Method One:
$ (' input[type= ' file '] '). On (' Change ', function () {
var reg =/[^\\\/]*[\\\/]+/g;//Match the name and suffix of the file
var name = $ (this). Val (). replace (Reg, ' ");
var postfix =/\. [^\.] +/.exec (name),//Get the suffix
of the file var text =name.substr (0,postfix[' index '));//Get name without suffix
//detect uploaded file
});
Method Two:
The following is just an example of a variable file that can be any string similar to a network path, an example of a file address that gets Name=file objects
Copy Code code as follows:
var file=jquery ("input[name= ' file ')"). Val ()
var filename=file.replace (/.* (\/|\\)/, "");
var fileext= (/[.] /.exec (filename))? /[^.] +$/.exec (Filename.tolowercase ()): ';
FileName gets filename
Fileext Get suffix Name
Method Three:
Most of the regular expressions found on the Internet do not take into account the Chinese folder and the Chinese filename.
Later, I wrote one by myself. After a lot of stray, I follow the Windows naming convention (the filename cannot contain the following characters://*? | "< >" Finally completes a regular formula that is considered to be more complete:
Copy Code code as follows:
([a-za-z]:) | (//)) (//) [^///*/?/|/: "<>]{1,255}) +/. (([j,j][p,p][g,g]) | ([g,g][i,i][f,f])
This expression is to determine whether the uploaded file type is jpg or GIF format. Test yourself, regardless of folder and filename is how to name, as long as you can find through Windows file management, can be correctly judged.
The above mentioned is the entire content of this article, I hope you can enjoy.