Re: What am i doing wrong :\
| From: | James | Date: | Mon, 12 May 2003 19:04:55 +0000 |
| Subject: | Re: What am i doing wrong :\ | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-147333@lists.php.net to get a copy of this message | ||
The answer is to read the manual on preg, since it is basically perl regex
you need to use "/[a-zA-Z0-9_]/".
Note the forward slashes.
<Clivus2k1@aol.com> wrote in message news:c6.1cc636e8.2bf13303@aol.com...
> Basicly its a simple to check to see if chars a-z,A-Z,0-9 and _ are added,
> why does this tell me both strings display illegal chars? :\
>
> <?
> function validc($text) {
> if (preg_match("[a-zA-Z0-9_]",$text)) { return 1; }
> else { return 0; }
> }
>
> $str = "moo-";
> if (!validc($str)) { echo("ERROR - $str contains illegal chars<br>"); }
>
> $str2 = "moo";
> if (!validc($str2)) { echo("ERROR - $str2 contains illegal chars"); }
> ?>
>
> Thanks for the help in advanced :-)
>