Re: validate names with regex
| From: | CPT John W. Holmes | Date: | Wed, 12 Nov 2003 22:08:41 +0000 |
| Subject: | Re: validate names with regex | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-169373@lists.php.net to get a copy of this message | ||
From: "Chris W. Parker" <cparker@swatgear.com>
> Can someone post a function or regex that can validate names (first and
> last)? The most important bit is that names like O'Malley and Hope-Jones
> are not barred.
I use this:
//allow a possible ', -, or space in name. ' will
//be replaced with \' by magic_quotes upon
//form submission (so we search for \\\')
$match = "^[a-z]+([- ]{1}|(\\\'))?[a-z]+$";
along with eregi(), but it can (should) be easily adapted to a syntax
compatible with preg_match().
I remember a large discussion about this a while back. Archives may be
useful.
---John Holmes...