Reputation: 726
I want to check my fileName which can be 2013_09_北京.doc
or 2013_09_广东_1.doc
or 2013_09_中国人_anywords.doc
,but I find that 2013_09_北京.doc
is checked OK,but 2013_09_广东_1.doc
seems wrong,what's wrong with my codes?
// fileName='2013_09_北京.doc';// right
fileName='2013_09_北京_1.doc';// wrong
var patt1 = new RegExp("^2013_(0[1-9]|1[0-2])_([\\u4e00-\\u9fa5]{2,3})(_[\S]*)?\.(doc)$");
if (!patt1.test(fileName)) {
alert('input format like 2013_09_北京.doc或2013_09_北京_1.doc’);
}
else
alert('right format!');
Upvotes: 0
Views: 85
Reputation: 4564
You did not escape \S and \. in your string, this should fix it:
var patt1 = new RegExp("^2013_(0[1-9]|1[0-2])_([\\u4e00-\\u9fa5]{2,3})(_[\\S]*)?\\.(doc)$");
Upvotes: 2