admin管理员组文章数量:1022944
matchArray bees null for input like asklas@(((#
How do I correct this behavior? I only want to allow characters and numbers..
function validateName(name) {
debug(name);
var namePat = /^(\[A-Za-z0-9]*)$/ ;
var matchArray = name.match(namePat);
if (!matchArray){
debug ("Invalid name,", name );
return false;
}
return true;
}
matchArray bees null for input like asklas@(((#
How do I correct this behavior? I only want to allow characters and numbers..
function validateName(name) {
debug(name);
var namePat = /^(\[A-Za-z0-9]*)$/ ;
var matchArray = name.match(namePat);
if (!matchArray){
debug ("Invalid name,", name );
return false;
}
return true;
}
Share
Improve this question
asked May 11, 2011 at 20:44
KiranKiran
5,52613 gold badges61 silver badges85 bronze badges
2 Answers
Reset to default 4There is one erroneous backslash in your regex. It should be
var namePat = /^[A-Za-z0-9]*$/;
(and you don't need the capturing parentheses, either).
Not sure what you want in this case... if you want a boolean output, use .test:
namePat.test(name)
... but null will work for your test (!matchArray)
just fine.
It does seem like you have a typo in your regular expression - you'll want to get rid of the backslash before the opening bracket...
matchArray bees null for input like asklas@(((#
How do I correct this behavior? I only want to allow characters and numbers..
function validateName(name) {
debug(name);
var namePat = /^(\[A-Za-z0-9]*)$/ ;
var matchArray = name.match(namePat);
if (!matchArray){
debug ("Invalid name,", name );
return false;
}
return true;
}
matchArray bees null for input like asklas@(((#
How do I correct this behavior? I only want to allow characters and numbers..
function validateName(name) {
debug(name);
var namePat = /^(\[A-Za-z0-9]*)$/ ;
var matchArray = name.match(namePat);
if (!matchArray){
debug ("Invalid name,", name );
return false;
}
return true;
}
Share
Improve this question
asked May 11, 2011 at 20:44
KiranKiran
5,52613 gold badges61 silver badges85 bronze badges
2 Answers
Reset to default 4There is one erroneous backslash in your regex. It should be
var namePat = /^[A-Za-z0-9]*$/;
(and you don't need the capturing parentheses, either).
Not sure what you want in this case... if you want a boolean output, use .test:
namePat.test(name)
... but null will work for your test (!matchArray)
just fine.
It does seem like you have a typo in your regular expression - you'll want to get rid of the backslash before the opening bracket...
本文标签: regexjavascript pattern matchingStack Overflow
版权声明:本文标题:regex - javascript pattern matching - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745595061a2158117.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论