0

I'm trying to make a JavaScript regexp such as the facebook uses for real names:

    Names can’t include:
  • Symbols
  • numbers
  • unusual capitalization
  • repeating characters or punctuation

source: Facebook help center
Here is my regexp:

 /^[a-z \,\.\'\-]+$/i

The problem with this regexp is that it doesn't check for repeated characters or punctuation:
then I found this :

/(.)\1/

so I'm now checking it like this:

$('input [type=text]).keyup(function(){
var name = $(this).val();
var myregex = /^[a-z\,\.\'\-]+$/i
var duplicate =  /(.)\1/
if(name != myregex.exec(name) ||  name == /(.)\1/)
{// the name entered is wrong
}
else
//the name is ok

but the problem I'm facing is with inputs like:

  • Moore
  • Callie
  • Maggie

what can I do to get the problem solved?

  • 3
    *"what can I do to get the problem solved?"* Stop trying to solve it. Names are both very complicated, and **very** personal. You're much better off doing data surveys and culling the obvious nonsense than really making people angry by refusing to honor their name. Your regex doesn't disallow it, but I've run into dozens of sites that won't allow "T.J." as a name. And all due respect to the people behind those sites, that's pure BS. My name is up to *me*, not them. Recommend you avoid causing similar offense. – T.J. Crowder Jan 01 '14 at 17:24
  • 3
    What if my name is Børre Ørevål or عبد الله or 汉/漢 – adeneo Jan 01 '14 at 17:25
  • @T.J.Crowder my site requires entering real names, as for privacy I made a system that keeps personal information **personal** –  Jan 01 '14 at 17:26
  • 5
    Falsehoods about names: http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/ – Lokno Jan 01 '14 at 17:26
  • Or for instance, Gerard 't Hooft. Is that capitalization "unusual"? – T.J. Crowder Jan 01 '14 at 17:27
  • @user689: You seem to be missing the point. More baldly: Don't implement a system that is likely to screen out people's real names. (Such as the examples adeneo gave you.) You will offend them. – T.J. Crowder Jan 01 '14 at 17:27
  • 1
    so should I just leave the whole idea? –  Jan 01 '14 at 17:30
  • 1
    I am very sure that "repeating chars" means **3 repeating chars** or more. Everything else doesn't make sense as many names have 2 repeating characters. This could have been described more clearly in that FB link you provided. – angabriel Jan 01 '14 at 17:32
  • 2
    @user689: That's my advice, yes. – T.J. Crowder Jan 01 '14 at 17:33
  • @T.J.Crowder seems validating names is more complex than what I thought, I'll leave the whole idea. But now what about this question should i delete it? –  Jan 01 '14 at 17:37
  • @user689: Probably, since it hasn't received any useful answers. Or if you like, I could post a "community wiki" (no rep) answer summarizing the above, and you can accept that, so that others looking to do the same thing will see it. – T.J. Crowder Jan 01 '14 at 17:38
  • @T.J.Crowder could you please post an answer. –  Feb 10 '14 at 18:32
  • @user689: Feel free to post your own answer summarizing the above, and accept it. That's perfectly fine on SO. – T.J. Crowder Feb 10 '14 at 18:34

1 Answers1

0

You should stop trying to solve this problem:

  • It is very complicated
  • Names are very personal

For instance your system will never be able to validate names from China or Japan.... (For instance: Børre Ørevål ,汉/漢 )

So just leave the whole idea, and let people freely enter their names with no restrictions.

Related: Regular expression for validating names and surnames?

Community
  • 1
  • 1