Re: preg_match problem
| From: | Jim Lucas | Date: | Thu, 25 Jan 2007 09:20:42 +0000 |
| Subject: | Re: preg_match problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-247771@lists.php.net to get a copy of this message | ||
Beauford wrote:
Plus a link to the source code for it. JimHere 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 Here is a link to a page that has this on it, but with the added "'"