Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript excel文件上载的正则表达式验证代码(Jquery)_Javascript_Jquery_Regex_Excel - Fatal编程技术网

Javascript excel文件上载的正则表达式验证代码(Jquery)

Javascript excel文件上载的正则表达式验证代码(Jquery),javascript,jquery,regex,excel,Javascript,Jquery,Regex,Excel,我想在上传时验证excel文件,我需要验证.xlsx |.xlsm |.xls文件 有人帮我吗。使用此代码 # Custom Method var file=$('#inpFile').val(); if (!(/\.(xlsx|xls|xlsm)$/i).test(file)) { alert('Please upload valid excel file .xlsx, .xlsm, .xls only.'); $(file).val(''); } else{

我想在上传时验证excel文件,我需要验证
.xlsx |.xlsm |.xls
文件

有人帮我吗。

使用此代码

# Custom Method 

var file=$('#inpFile').val();

if (!(/\.(xlsx|xls|xlsm)$/i).test(file)) {
    alert('Please upload valid excel file .xlsx, .xlsm, .xls only.');
    $(file).val('');
}
else{
    alert('File uploded')// write your code here to upload file
}

#  Another Way to validate 

$('#upload').validate({
    rules: {
        resume: {
            required: true,
            extension: "xlsx|xls|xlsm"
        }
    },
    messages: {
        resume: {
            required: "file .xlsx, .xlsm, .xls only.",
            extension: "Please upload valid file formats .xlsx, .xlsm, .xls only."
        }
    }
});
我希望它对你有用


谢谢。

如果您想只验证扩展,请使用此扩展


那有什么问题?它不起作用了。如果我也添加excel文件..您想只验证文件扩展名,还是同时验证文件名?@dr_dev文件名(字母数字和特殊字符)和扩展名。@Kasra,扩展名验证对我来说已经足够了。你能帮忙吗。
jQuery("#upload").validate({
        expression: "if (VAL.match(/\.(xls[mx]?)$/) && VAL) return true; else return false;",
        message: "Please upload valid excel file"
});