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 ) ) ) ?> Cheers, Rob. -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php