Re: Silly RegEx - Looks good to me

From: Date: Fri, 15 Dec 2000 17:10:09 +0000
Subject: Re: Silly RegEx - Looks good to me
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-30539@lists.php.net to get a copy of this message
On Fri, 15 Dec 2000, JB wrote: > Hey, > > Here's an easy one for someone to field. I do these regex validations in just about every > piece of code I write with forms, so I'm a little baffeled why it doesn't work, cus it > looks good to me. > > if ($name=="" || eregi("[^a-z0-9\.-][[:space:]]", $name)) { The problem is here ^^ > print "ERROR, Please fill out this field, and use alphanumerical characters > only!"; > } > > Basically if the field is left empty or contains anything but alphanumeric hypen period or > space it should print the error message. > However, entering something like !@#$%^&*(+_* passes right through the regex.. no error > message is displayed. Whats the prob here? Thanks. > > Jason > What you want is: eregi("[^a-z0-9\.-[:space:]]", $name) -- Ignacio Vazquez-Abrams <ignacio@openservices.net>

« previous php.general (#30539) next »