On Mon, Oct 26, 2009 at 4:16 PM, Yogesh Agashe <yogesh.aga...@gmail.com>wrote:
> [...] > Konstantin K wrote: > > oh and also allow for . (periods).... > > On Mon, Oct 26, 2009 at 4:06 PM, Konstantin K <kkru...@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/
_______________________________________________ New York PHP Users Group Community Talk Mailing List http://lists.nyphp.org/mailman/listinfo/talk http://www.nyphp.org/Show-Participation