Re: help with preg_match
| From: | Tracy Finifter Rotton | Date: | Sat, 04 Jan 2003 17:28:27 +0000 |
| Subject: | Re: help with preg_match | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-130235@lists.php.net to get a copy of this message | ||
You need to tell preg_match that there will be multiple characters. Right
now, you're searching for one, and only one.
if (! preg_match ('/^[a-z0-9]+$/', $unchecked_text)) {
The "+" means one or more matches to the range in brackets.
-- tracy
On 1/4/03 9:03 AM, "Anders Thoresson" <listor@thoresson.net> wrote:
> Hi,
>
> I'm trying to write a function that validates the input in a textarea. I
> just want to allow alphanumrical characters, and if the user enters
> anything else, I display an error message by calling error().
>
> But the following doesn't work. Even if I enter "hello" in the textarea,
> I get the error message. What am I missing?
>
>
> // validate entered text in textarea
>
> function validate_textarea($unchecked_text) {
>
> if (!preg_match ("/^[a-zåäö0-9]$/is", $unchecked_text)) {
> error("You have used unlegal characters, just alphanumeric is ok.");
> }
> }
>
> Best regards,
>
> Anders
>
--
Tracy F. Rotton
tracy@taupecat.com
http://www.taupecat.com/
"... I like the 49ers because they're pure of heart,
Seattle because they've got something to prove,
and the Raiders because they always cheat."
-- Lisa Simpson, "Lisa the Greek"