Re: preg_match problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Beauford wrote:
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

Here is a link to a page that has this on it, but with the added "'"

Plus a link to the source code for it.

Jim

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux