Jump to content

Alphanumeric Checking


mike177

Recommended Posts

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.

Link to comment
Share on other sites

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");
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.