Re: Regular expression problems

From: Date: Mon, 14 Apr 2003 15:50:08 +0000
Subject: Re: Regular expression problems
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-143796@lists.php.net to get a copy of this message
> I am using a regular expression to try and weed out unwanted characters > in user input. What I am trying to do, is allow input to contain > alpha-numeric characters and some other standard characters e.g. "-", > "!", "&", etc. I am trying to accomplish this like so: > > else if > (eregi("^[a-zA-Z0-9!@#\$%^&\*\(\),/.//<>\?;':\"~`_\+\|\\-\\t\n\ > ]*$", $sessname)) > return true > > The problem is that this regular expresion returns FALSE if there is a > "-" character anywhere in the input. Anyone offer any pointers? The "-" character needs to be last within the brackets, otherwise the regex parser will think you're looking for a range of characters. [a-zA-z-] will allow upper/lowercase letters and the "-" character. ---John Holmes...

« previous php.general (#143796) next »