我有一个字段,您可以在其中输入您的姓名并提交。我想接收人们的名字和姓氏,为此我需要检查该值是否包含至少 2 个单词。这是我现在正在使用的,但似乎不起作用。
function validateNameNumber(name) {
var NAME = name.value;
var matches = NAME.match(/\b[^\d\s]+\b/g);
if (matches && matches.length >= 2) {
//two or more words
return true;
} else {
//not enough words
return false;
}
}
str.trim().indexOf(' ') != -1 //there is at least one space, excluding leading and training spaces
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)