📅  最后修改于: 2022-03-11 15:02:36.779000             🧑  作者: Mango
//If your code above is simply trying to get the file extension of the filename then you can split the filename to an array by . and then use pop(). You can also put the valid extensions in an array and use indexOf() to check for validity. Try this:
var validExt = [ 'pdf', 'jpg', 'png' ];
var ext = this.value.split('.').pop();
if (validExt.indexOf(ext.toLowerCase()) == -1) {
alert('Not allowed file type');
this.value = '';
}