NYCPHP Meetup

NYPHP.org

[nycphp-talk] Valudating common field types

David Mintz vtbludgeon at gmail.com
Mon Oct 26 16:29:37 EDT 2009


On Mon, Oct 26, 2009 at 4:16 PM, Yogesh Agashe <yogesh.agashe at gmail.com>wrote:

>  [...]
> Konstantin K wrote:
>
> oh and also allow for . (periods)....
>
> On Mon, Oct 26, 2009 at 4:06 PM, Konstantin K <kkrutoi at gmail.com> wrote:
>
>> be careful. don't just check if the field is NON empty.  that's not good
>> enough.
>>
>> in English, you can reasonably assume the following to be true about
>> names:
>> - must contain at least 1 letter [A-Za-z]
>> - may contain ' (apostrephe) and - (dash) and  (space)
>> - shouldn't be longer than 40 characters.
>> - should not contain #s, or any other symbol, especially < (so ppl don't
>> start entering html codes, js, etc)
>>
>
Some time ago I borrowed and stole and cobbled together this regex for a
first name:

/[^a-zA-Z\xC0-\xFF ]/

This is your whitelist approach. You test if the value contains anything
other than this; if it doesn't, it's good. Min and max lengths have to be
checked separately, though if you are really a ninja I think this could be
made part of the regex.

I allow space because there may be a 'Marie Christine' or some such who
really wants the two parts regards as a single first name. The \x stuff
allows a slew of chars found in Western European languages, so you're
somewhat internationalized. If memory serves I think I got that from Daniel
C.

My surname validator is the same except that it permits ' (apostrophe).


-- 
Demand health care for everyone:
http://mobilizeforhealthcare.org/

--
David Mintz
http://davidmintz.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20091026/f9eca021/attachment.html>


More information about the talk mailing list