Is this the perfect regex for validating first & last names?

Perhaps a fairly bold statement, coming from a novice regex'er. :slight_smile:

I'm creating a form (php) and have conjoured up this regex.

My objective with this regex is to be sure I get a valid person's name.
With that, I am assuming a real name does not contain 0-9, punctuation
chars, programming symbols, and so on. I'm allowing more than one part
names, like "Mary Beth" and "de la Cruz", and I'm being flexible in case
the use more than one blank between names. I've included all the
diacritics I could find (except the a-e character that is merged - is
this still in use?)

Anyway, feedback is appreciated. Here it is:

function valid_name($name) {
聽聽return eregi("^(([a-z谩脿芒盲茫氓莽茅猫锚毛铆矛卯茂帽贸貌么枚玫煤霉没眉脽每])+( ?)*)+$", $name) ;
}

Please excuse for the php format. Prior to the function being called,
whitespace is stripped front and back. eregi is a case insensitive
match.

A person certainly could enter a sentence or phrase (w/o punctuation, of
course) and it would be accepted as a valid name. However, that's
beyond the scope of what I'm trying to do with the regex.

Fire away!

Thanks, Todd

路路路

--
Posted via http://www.ruby-forum.com/.

Todd Burch wrote:

Perhaps a fairly bold statement, coming from a novice regex'er. :slight_smile:

Well, shucks. I missed the hyphenated last name condition. Hillary
Rodham-Clinton would get bounced... (but maybe that's ok? LOL)

路路路

--
Posted via http://www.ruby-forum.com/\.

Perhaps a fairly bold statement, coming from a novice regex'er. :slight_smile:

I'm creating a form (php) and have conjoured up this regex.

Are you really sure you want to ask a PHP question in a Ruby forum? I
guess you'll get a better answer in a PHP forum.

My objective with this regex is to be sure I get a valid person's name.
With that, I am assuming a real name does not contain 0-9, punctuation
chars, programming symbols, and so on. I'm allowing more than one part
names, like "Mary Beth" and "de la Cruz", and I'm being flexible in case
the use more than one blank between names. I've included all the
diacritics I could find (except the a-e character that is merged - is
this still in use?)

Sure it is (in Danish an Norwegian). And there's the 酶 character. Oh and
those (and a few others) could also be upper case ...

Urban

路路路

On Aug 18, 2007, at 19:39 , Todd Burch wrote:

Todd Burch <promos@burchwoodusa.com> writes:

Perhaps a fairly bold statement, coming from a novice regex'er. :slight_smile:

I'm creating a form (php) and have conjoured up this regex.

My objective with this regex is to be sure I get a valid person's name.
With that, I am assuming a real name does not contain 0-9, punctuation
chars, programming symbols, and so on.

<snip>

Anyway, feedback is appreciated. Here it is:

function valid_name($name) {
  return eregi("^(([a-z谩脿芒盲茫氓莽茅猫锚毛铆矛卯茂帽贸貌么枚玫煤霉没眉脽每])+( ?)*)+$", $name) ;
}

I don't know PHP regular expressions, but a bit of googling suggests
that you can use standard POSIX character classes, so I'd replace that
list of letters with [[:alpha:]]. You also have some extraneous
parentheses that could be stripped away, so that leaves you with:

   return eregi("^([[:alpha:]]+(-| +)?)+$", $name) ;

That adds in the hyphenated name thing, but disallows something like:
   Hillary Rodham--Clinton
or
  Hillary Rodham- Clinton
You're allowed either some number of spaces or a single dash between
words, but not multiple dashes or both a dash and a space.

At this point, if it isn't working you may be stuck in locale and/or
character set encoding issues. Working those out is left as an
exercise for the one of us closer to the PHP install. A word of
warning: i18n can drive you positively batty if you let it.

路路路

--
s=%q( Daniel Martin -- martin@snowplow.org
       puts "s=%q(#{s})",s.to_a.last )
       puts "s=%q(#{s})",s.to_a.last

So no R2D2, or K-9? :wink:

Alec

路路路

In message <761c72b492471cd116292b3af045a164@ruby-forum.com>, Todd Burch <promos@burchwoodusa.com> writes

Perhaps a fairly bold statement, coming from a novice regex'er. :slight_smile:

I'm creating a form (php) and have conjoured up this regex.

My objective with this regex is to be sure I get a valid person's name.
With that, I am assuming a real name does not contain 0-9,

--
Alec Ross

Most assumptions about names turn out to be wrong.

http://en.wikipedia.org/wiki/List_of_personal_names_that_contain_numbers

Note names like Jennifer 8. Lee, Perri 6, Nancy 3. Hoffman.

Good luck!

-A

路路路

On 8/18/07, Todd Burch <promos@burchwoodusa.com> wrote:

Perhaps a fairly bold statement, coming from a novice regex'er. :slight_smile:

I'm creating a form (php) and have conjoured up this regex.

My objective with this regex is to be sure I get a valid person's name.
With that, I am assuming a real name does not contain 0-9, punctuation
chars, programming symbols, and so on.

Todd Burch wrote:

Todd Burch wrote:

Perhaps a fairly bold statement, coming from a novice regex'er. :slight_smile:

Well, shucks. I missed the hyphenated last name condition. Hillary
Rodham-Clinton would get bounced... (but maybe that's ok? LOL)

Revised to allow hyphens:

"^(([a-z谩脿芒盲茫氓莽茅猫锚毛铆矛卯茂帽贸貌么枚玫煤霉没眉脽每])+(\-?|( ?)*))+$"

路路路

--
Posted via http://www.ruby-forum.com/\.

Todd Burch wrote:

Revised to allow hyphens:

"^(([a-z谩脿芒盲茫氓莽茅猫锚毛铆矛卯茂帽贸貌么枚玫煤霉没眉脽每])+(\-?|( ?)*))+$"

Well, so much for testing my own code. "z谩" fails. All the diacritics
fails.

Back to the drawing board.

路路路

--
Posted via http://www.ruby-forum.com/\.

Urban Hafner wrote:

Are you really sure you want to ask a PHP question in a Ruby forum? I
guess you'll get a better answer in a PHP forum.

Actually, it's a regex question. Lots of regex questions and answers
get posted here. Lots of regex expertise here. Is there a regex forum
somewhere else I should be using? I could have dummied this up to
look like it was in ruby, or, not even mentioned php I guess.

Your "other" character example did not show up.

Thanks, Todd

路路路

--
Posted via http://www.ruby-forum.com/\.

Alex LeDonne wrote:

Most assumptions about names turn out to be wrong.

http://en.wikipedia.org/wiki/List_of_personal_names_that_contain_numbers

Note names like Jennifer 8. Lee, Perri 6, Nancy 3. Hoffman.

Good luck!

-A

HA HA. Seeing as there are so few, I think I'll copy those names into
an array and specifically reject them. LOL. I joked around with some
buddies back in the mid 80's about prefixing my first kid's name with
"DSN@", as the code we were working on at the time contained a lot of
modules with this prefix. We got a good laugh out of it. Never did do
it though - the wife (http://imdb.com/title/tt0092746/\) wouldn't have
gone for it.

I worked the regex out to my satisfaction. I was taking the wrong
approach. I decided to reject invalid characters, or what I consider to
be invalid characters for a human name on our planet, instead of only
accepting valid characters. Shorter, simpler, and it met my other goal
of being one facet of stopping a potential spam injection as well.

Todd

路路路

--
Posted via http://www.ruby-forum.com/\.

Todd Burch wrote:

Urban Hafner wrote:

Are you really sure you want to ask a PHP question in a Ruby forum? I
guess you'll get a better answer in a PHP forum.

Actually, it's a regex question. Lots of regex questions and answers
get posted here. Lots of regex expertise here. Is there a regex forum
somewhere else I should be using? I could have dummied this up to
look like it was in ruby, or, not even mentioned php I guess.

Your "other" character example did not show up.

Thanks, Todd

Just that ereg* is not pcre. There is no equivalent in ruby to the ereg*
functions.

Regards
Stefan

路路路

--
Posted via http://www.ruby-forum.com/\.

A great place for RegEx:
www.regexlib.com

Stefan Rusterholz wrote:

Todd Burch wrote:

Just that ereg* is not pcre. There is no equivalent in ruby to the ereg*
functions.

Regards
Stefan

Ok then. I'll find the proper resource. Thanks.

路路路

--
Posted via http://www.ruby-forum.com/\.