Re: Regular Expression
| From: | CC Zona | Date: | Tue, 13 Nov 2001 08:46:27 +0000 |
| Subject: | Re: Regular Expression | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-74386@lists.php.net to get a copy of this message | ||
In article <OF650E5327.E282F0EA-ON69256B03.00273E65@compsm.com.au>,
Adam.Whitehead@compsm.com.au (Adam Whitehead) wrote:
> if ((ereg("[^[:alnum:]]",$fn)) || (ereg("[^[:alnum:]]",$sn))) {
> // Do something here
> }
>
> What it's doing is checking two variables to make sure they contain only
> alphanumeric characters.
>
> I have a requirement that hyphens (-) be allowed in $fn and $sn as well.
> What do I need to add to the regular expression to allow hyphens?
Insert it as the last item in the character class:
[^[:alnum:]-]
--
CC