RE: [PHP] preg_match problem

From: Date: Wed, 24 Jan 2007 21:13:19 +0000
Subject: RE: [PHP] preg_match problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-247719@lists.php.net to get a copy of this message
> Here is my rendition of what I think you are looking for. > > $str = 'tab( )/space( )/path-asdf\asdf_!@#$%^&*();:...'; > > if ( preg_match('|^[a-zA-Z0-9!@#$%^&*();:_.\\\\ /\t-]+$|', $str) ) { > echo 'success'; > } else { > echo 'failure'; > } > Here is the problem, and it is strange. If I enter each of the above characters into my form one at a time and hit submit after each one, NO error is produced for any of them. If I cut and past this all at once: a-zA-Z0-9!@#$%^&*();:_.\ then an error IS returned. If I continue to remove one character at a time, submitting the form each time, errors ARE still produced. This is the code in a nutshell: If(isset($submit)) { $name = stripslashes($_POST['name']); >> I have tried this with and without $formerror = array(); unset($result); >> I have tried this with and without if($result = ValidateString($name)) { $formerror['name'] = $invalidcharacters; Function ValidateString($string) { if (!preg_match('|^[a-zA-Z0-9!@#$%^&*();:_.\\\\ /\t-]+$|', $string) ) { return invalidchars; } } } <Form Stuff> <input name="name" size="30" type="text"> </form> Thanks

« previous php.general (#247719) next »