RE: Ereg problem

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

 




-----Original Message-----
From: Robert Cummings [mailto:robert@xxxxxxxxxxxxx] 
Sent: June 27, 2006 12:58 PM
To: Beauford
Cc: PHP-General
Subject: Re:  Ereg problem

On Tue, 2006-06-27 at 12:14, Beauford wrote:
> One more in my recent woes. The last elseif does not work in the code 
> below
> - even if the string is correct it always says it's incorrect. Even if 
> I remove everything else and just have the ereg satement is doesn't 
> work either.
> 
> The code below is in a function and $_POST['password1'] is passed to 
> the function.
> 
>       $field = "password1";  //Use field name for password
> 
>       if(!$subpass){
>          $form->setError($field, " Password not entered");
>       }
> 	elseif(strlen($subpass) < 6) {
> 	  		$form->setError($field, " Too Short");
> 	}
> 	elseif(strlen($subpass) > 10) {
> 	  		$form->setError($field, " Too Long");
> 	}
>       elseif(!ereg('[^A-Za-z0-9]', trim($subpass))) {
> 			$form->setError($field, " Not alphanumeric"); 
> 	}

You're double negating. You check the negative return of ereg() and ereg
checks for the pattern NOT existing.

<?php

    elseif( !ereg( '[A-Za-z0-9]', trim( $subpass ) ) )

    // the ereg check is still wrong though and should be...

    elseif( !ereg( '^[A-Za-z0-9]+$', trim( $subpass ) ) )

    // though personally, I'd use the following...

    elseif( !ereg( '^[[:alnum:]]+$', trim( $subpass ) ) )

?>

Ahhh, I was thinking of it the other way round.  Thanks.

-- 
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