[nycphp-talk] validating proper name capitalization
justin
justin at justinhileman.info
Fri Sep 23 10:41:46 EDT 2011
You might be better off enumerating "goodness"...
/^
([A-Z][a-z]+)+ # first name, consisting of any
number of AbAbc, handles "LaDawn"
\s+
( # middle name (optional)
[A-Z] # at the very least, has a capital letter
(
\. # ends with either a dot
| # ... or ...
[a-z]+([A-Z][a-z]+)? # the rest of a name
)? # but again, that's totally optional
\s+
)?
([A-Z][a-z]+)+ # and a last name, following the
same convention as the first (McGraw)
$/x
-- justin
On Fri, Sep 23, 2011 at 6:54 AM, David Mintz <david at davidmintz.org> wrote:
> I'm trying to require users to input proper names with capitalization that
> conforms to convention. So, you can't go e. e. cummings on me, and you can't
> be JOHN SOMEBODY either. And you can't have your caps lock on and enter jOHN
> sOMEBODY. That much is pretty easy, but I am finding the more subtle cases
> pretty hard.
>
> So far, I have
>
> /\b[a-z][A-Z]+|\b[A-Z]{2,}+|^[a-z ]+$/
>
> to test against (false is good). This works on all the cases I have tested
> except "cuMmings," which gets by. But I am thinking, maybe enough is enough;
> you can't control everything.
>
> Just wondering if anyone has tackled this before or has any thoughts.
>
>
--
http://justinhileman.com
More information about the talk
mailing list