繁体   English   中英

JavaScript; 如何要求文件的特殊命名

[英]JavaScript; How to require special naming of files

我正在尝试通过JavaScript验证上传的文件具有特殊的文件名。 我希望我的文件具有这种结构; EN1234567890.wav。 这意味着文件名的前两个字符应为字母,后10个字符应为数字。 扩展无关紧要,因为我为此使用了其他验证器。 文件名(不带扩展名)应始终为12个字符。

这是我的脚本;

var filename = fullfilepath.replace(/^.*[\\\/]/, '');

if (!filename.match(/^[0-9a-zA-Z\.]*$/)) {
    alert('File name should only containg letters and numbers, please rename image file and upload.');
}

该脚本仅检查文件名中的字母和数字,而不检查我的“拥有”结构之后。 我该如何工作?

使用重复标记:

/[a-zA-Z]{2,2}[0-9]{10,10}/

http://www.regexpal.com/?fam=93635

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM