[thelist] RegExp for name validation...
jsWalter
jsWalter at torres.ws
Mon Dec 15 17:01:08 CST 2003
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
More information about the thelist
mailing list