[thelist] RegExp for name validation...

Andrew Seguin asegu at borg.darktech.org
Mon Dec 15 18:00:54 CST 2003


ok, I won't ask why... nor can I quickly offer a complete solution...

but, why not...
1-why not split into more then one ereg? Validate your rules a couple at a
time?
  $name = "a-sample n'me"
  if (
       ereg("([a-z...<allowedChars>]) ([a-z...<allowedChars>])", $name)
    && ereg(...)
  ) /*Then valid name*/ else /*invalid name*/

2-Could the name be input taken as two(more?) parts? does it have to come
in as one string? I'm thinking here that you could always leave it up to
the user to decide what they want to show up as first/last name.

Of course their could be a good reason to do take it in as a single string
(maybe going through a text file or what not)...

..so extension of point 2... could the regular expressions be kept strict
and user confirmation if regular expressions are unable to process
properly? Cause I'm thinking that you might end up with problems in other
cultures names where maybe it could be acceptable to have multiple
apostrophees within...or maybe they might want to write their name as
'last_name', 'first name'...

At this point... I'm thinking a good PhD in computer science - natural
language processing could start to be of use ;)

Good luck on your (intriguing, I'll admit) quest for your name matching
regular expression.

Andrew

> These are my rules...
>
> assuming:
>  - a SPACE is used to delimit first from last name [Walter Torres]
>  - a HYPHEN is used to separate a dual name (British style) [Conrad-Smyth]
>  - an APOSTROPHE is used in many Irish and Scottish names [o'Rielly]
>  - a PERIOD is used in titles, suffixes [Dr. Sr. Jr.]
>  - a PERIOD is used for Initials [Walter G. Torres]
>
> then...
>  - allow apostrophes, but only if preceded *and* followed by a
> Alpha/Extend
>  - allow hyphen/dash, but only if preceded *and* followed by a
> Alpha/Extend
>  - allow PERIOD, but only if preceded by a Alpha/Extend *and* followed by
> a
>    SPACE or EOS
>  - allow SPACE, but only if preceded *and* followed by a Alpha/Extend
>
> Here are my examples, the last three have extended characters which may or
> may not show up in your version of this message)...
>
>    Dr. Roger O'Malley
>    Mrs. Sara Harris-Henderson
>    Manuel González
>    Försök Bokstäver
>    Contém Espaço-Válido
>
> This is what I've made to date...
>
>    /^([a-z\x80-\xFF]+(. )?[ ]?)+$/i;
>
> It works, sort of.
>
>  - it does not handle the HYPHEN or apostrophe rule.
>  - it allows (multiple) spaces at the end.
>
> I'm hoping someone smarter than me can see how to make this work as
> desired.
>
> And please, I can't defend why this is the way it is, and I can't defend
> against numbers and punctuation in names. So please, I beg you, if you are
> going to demand to know why I "need this" and/or why I don't allow numbers
> or punctuation in names, you can save your energy and electrons. (Yes,
> I've
> gotten this from 3 other lists)
>
> I'm always open to constructive criticism. Better ways of doing things.
> Learning more than I know.
>
> I'm not open to explaining why I'm asking to d something in a certain way,
> or why "the rules are that way". 9 times out of 10 the reason for a
> question
> in a certain manner is because the client demands it.
>
> the 10th time is because I didn't think of a better way.
>
> I've always tried to answer the question given on lists like this, and if
> I
> see "better way", then I offer it. I really think it's rude to ask why
> someone asks for something in a certain way, without explaining the down
> fall of the method suggested and without suggesting a better method, all
> in
> the same message.
>
> But then, that's me.
>
> Sorry, too many "why do you need this" message today.
>
> thanks for your help.
>
> This group has always been more than generous with its talent.
>
> Walter
>
>
> --
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !
>
>



More information about the thelist mailing list