mike177 Posted January 20, 2008 Share Posted January 20, 2008 Hi, I am constantly posting new topics on this forum now due to the fact it’s highly used and the members actually help solve your problem. Anyway I need to check my passwords to be alphanumeric. I have tried using preg_match, ereg, eregi and many more but they just aren't working I have tried all possible configurations with my script but none can do the job. I have a file that handles the error handling so none is in the section below, It's just the password processing. If you could give some suggestion’s it would be great and thanks in advance for any help. /*Password error checking*/ $field = "pass"; if(!$subpass){ $form->setError($field, "* Password Not Entered"); } else{ /*Spruce up password and check length*/ $subpass = stripslashes($subpass); if(strlen($subpass) < { $form->setError($field, "* Password must contain 8-15 characters"); } else if(strlen($subpass) > 15){ $form->setError($field, "* Password must contain 8-15 characters"); } else if(!eregi("^([0-9a-z])+$", ($subpass = trim($subpass)))){ $form->setError($field, "* Password must be alphanumeric"); } } Keep in mind that this is only a section of the file, it works fine its just the alphanumeric error checking wont work in the last else if statment. Quote Link to comment Share on other sites More sharing options...
werty37 Posted January 20, 2008 Share Posted January 20, 2008 Hi mike, I am using this in one of my scripts and it seems to work for me. This should work for you hopefully if (!preg_match('/^[\w\d\_\.]{8,15}$/',$var)) { // code } Regards Sujith Quote Link to comment Share on other sites More sharing options...
Nhoj Posted January 20, 2008 Share Posted January 20, 2008 I always use something like this: if (!ctype_alnum($password)) { // The password is not alphanumeric } http://us3.php.net/manual/en/function.ctype-alnum.php Quote Link to comment Share on other sites More sharing options...
mike177 Posted January 20, 2008 Author Share Posted January 20, 2008 I always use something like this: if (!ctype_alnum($password)) { // The password is not alphanumeric } http://us3.php.net/manual/en/function.ctype-alnum.php Hey thanks for the help but it's not working. This is how I have it in my script. else if (!ctype_alnum($subpass)) { $form->setError($field, "* Password must be alphanumeric"); } Quote Link to comment Share on other sites More sharing options...
mike177 Posted January 20, 2008 Author Share Posted January 20, 2008 Hi mike, I am using this in one of my scripts and it seems to work for me. This should work for you hopefully if (!preg_match('/^[\w\d\_\.]{8,15}$/',$var)) { // code } Regards Sujith ------------------- Hi, I've tried your method and the same result persists. Do you think it may be somthing more than the script. Quote Link to comment Share on other sites More sharing options...
revraz Posted January 20, 2008 Share Posted January 20, 2008 echo $subpass and see what it contains. Nhoj's example should work fine. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.