为什么名称验证无效?

时间:2017-02-11 11:09:35

标签: javascript regex validation google-chrome

为什么用户输入时名称无效:

André
René
François
Anne-Marie

CODE:

var myNameFilter = /^([a-zA-Z ]+)$/;
var a = $('#firstname').val();
if(a=='') {
  alert("You stupid your name is empty. Fill it in NOW!!!");
  return false;

} else if (!myNameFilter.test(a)) {
    alert("Are you stupid? how can you type your name wrong. you idiot. fix it, dont call me for this.");
    return false;
} 

1 个答案:

答案 0 :(得分:1)

[a-zA-Z]仅检测英语。它们包含unicode字符,因此它不会检测到它。 现在检查



var a="André,René,Fran çois,Anne-Marie,éç,é-çé ç,Éric,Hélène".split(",");
var myNameFilter = /^([a-zA-Z\-éçèàùâêîôûëïüÿçÉ\s]+)$/;
i=0;
while(i<a.length){
 console.log(a[i]+"->"+myNameFilter.test(a[i]));
  i++;
}
&#13;
&#13;
&#13;