RE: [PHP] Form Validation: Surnames with Apostrophe

From: Date: Thu, 13 Mar 2003 01:36:03 +0000
Subject: RE: [PHP] Form Validation: Surnames with Apostrophe
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-139427@lists.php.net to get a copy of this message
> > preg_match ( "/[A-Za-z-']+/", $_POST['Last_Name'] ); > > > > tpc@csua.berkeley.edu wrote: > > > I have been trying to validate a form field Last_Name and have been > unable > > > to find a regexp to account for the apostrophe (e.g., O'Reilly). The > > > following statement: > > > > > > preg_match('/^[[:alpha:]]+[-]?[[:alpha:]]+$/', $_POST[Last_Name]) > > > > > > accepts hyphenated surnames and I have tried escaping the apostrophe: > > > [\\'] and [\\\'] to no avail. Any idea what I am doing wrong? > that could work but the user may now submit one or more apostrophes > as the Last Name. Watch out for magic_quotes. If "O'Reilly" is submitted, unless you stripslash() it, you're validating against "O\'Relly". preg_match("/[a-z](\\')?[a-z-]+/i",$_POST['Last_Name']) ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/

« previous php.general (#139427) next »