1

Why the name is not valid when user is type:

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;
} 
weston
  • 51,132
  • 20
  • 132
  • 192
  • because all these names contain characters not matched by your character class: `é`, `ç` and `-` – Sebastian Proske Feb 11 '17 at 11:12
  • How can i allow all those none standard characters? (all those french, dutch people have awkward characters). –  Feb 11 '17 at 11:13
  • Name validation is a hard task and there will always be a name that kills your regex: http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/ – Sebastian Proske Feb 11 '17 at 11:17
  • look at [this](http://stackoverflow.com/questions/42074834/regex-for-a-user-name-in-javascript-a-name-not-a-username/42174979#42174979) - name validation – Maciej Kozieja Feb 11 '17 at 11:18

1 Answers1

0

[a-zA-Z] detect only english. they contain unicode characters and so it will not detect it. Now check it

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++;
}
Sagar V
  • 11,083
  • 7
  • 41
  • 62