Re: regular expressions question
| From: | Shawn McKenzie | Date: | Tue, 04 Mar 2008 20:04:37 +0000 |
| Subject: | Re: regular expressions question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-270967@lists.php.net to get a copy of this message | ||
Adil Drissi wrote:
> Hi,
>
> Is there any way to limit the user to a set of characters for example say i want my user to
> enter any character between a and z (case insensitive). And if the user enters just one letter not
> belonging to [a-z], this will not be accepted.
>
> I tried eregi('[a-z]', $fname) but this allows the user to enter abdg4512kdkdk for
> example.
>
> Thank you
>
>
> ---------------------------------
> Never miss a thing. Make Yahoo your homepage.
Keeping with your example, this works and doesn't allow an empty string
(to allow empty, replace the + with *):
eregi('^[a-z]+$', $fname)
-or-
ereg('^[A-Za-z]+$', $fname)
But ctype_alpha() is a better multi-locale solution.
-Shawn