[thelist] REG EX & PHP ---> Ha.

Stephane Gosselin stef at cfusions.com
Fri May 17 08:17:01 CDT 2002


  Hi . I have an issue wich may be a tip... if I'm wrong plz correct me cuz
I struggled a couple of hours with this one.

<tip type="php">
I wanted a regex in a script to accept anything  that was alphanumeric,
(A-Z, a-z, 0-9) , any dashes, any lines.

This one did the job fine:
if(!ereg("^[a-zA-Z0-9\/_/-]+$",$num_prod))

Now. I wanted to be able to accept whitespace. The following, simple
adjustement SHOULD of worked:

if(!ereg("^[a-zA-Z0-9\/_/-/s]+$",$num_prod))

But failed. Turns out... if your url is coming from a query string, DO take
into account the % ! ! !

SO:

if(!ereg("^[a-zA-Z0-9\/_/-/s/%]+$",$num_prod))

WORKS PERFECT !
</tip>




More information about the thelist mailing list