我正在尝试验证是否只使用了某个文件扩展名,但如果文件名中有句点或根本没有扩展名,我的正则表达式会失败。对此的任何帮助将不胜感激。谢谢!
当前代码:
// this looks at what file type was attemped and validates it
$('INPUT[type="file"]').change(function () {
var ext = this.value.match(/\.(.+)$/)[1];
switch (ext) {
case 'bmp':
case 'doc':
case 'xls':
$('#publicSubmit').attr('disabled', false);
break;
default:
alert('This is and invalid file extension. Vaild extension(s): bmp, doc, xls');
//$('#publicSubmit').attr('disabled', true);
this.value = '';
}
});