使用正则表达式确保上传的文件input[type="file"]
是 MP3。出了点问题,我正在测试的文件没有通过。
谢谢你的帮助!
HTML
<input type="file"/>
JavaScript
var file = $input.find('input[type="file"]'),
val = file.val(),
type = /^([a-zA-Z0-9_-]+)(\.mp3)$/;
submit.attr('disabled', 'disabled').addClass('deac');
if (!val){
modal("The upload can't be empty.", true);
} else if (!type.test(val)){
modal("The song must be in MP3 format.", true);
/***********
*
* Getting caught here- even with a valid .mp3 file that _should_ pass the regex
* in my test case using mamp as a localhost, val = C:\fakepath\1.mp3
*
***********/
} else {
/* Success */
}