RE: [PHP] Form Validation: Surnames with Apostrophe
| From: | tpc at csua dot berkeley dot edu | Date: | Thu, 27 Mar 2003 23:04:49 +0000 |
| Subject: | RE: [PHP] Form Validation: Surnames with Apostrophe | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-141329@lists.php.net to get a copy of this message | ||
When I do that:
(preg_match("/^[a-z](\\')?[a-z-]+$/i",$_POST[Last_Name])
it won't allow O'Reilly
and seems to not allow anything at all
On Thu, 27 Mar 2003, Jennifer Goodie wrote:
> That is because it is not saying that is all that can be in the string. The
> 'Re' matches that pattern. Put a ^ at the beginning to signify it must
> start with the pattern and a $ at the end to signify it must end there.
>
> -----Original Message-----
> From: tpc@csua.berkeley.edu [mailto:tpc@csua.berkeley.edu]
> Sent: Thursday, March 27, 2003 1:19 PM
> To: John W. Holmes
> Cc: 'John Nichel'; php-general@lists.php.net
> Subject: RE: [PHP] Form Validation: Surnames with Apostrophe
>
>
>
> I just tried your regexp:
>
> (preg_match("/[a-z](\\')?[a-z-]+/i",$_POST[Last_Name])
>
> and it allows the following:
>
> O' #$%@Re
>
> It seems to allow any number of characters and spaces between the O' and
> Re
>
> On Wed, 12 Mar 2003, John W. Holmes wrote:
>
> > > > 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/
> >
> >
> >
>
>