Jump to content


Photo

validating alpha-numeric password


  • Please log in to reply
3 replies to this topic

#1 bcamp1973

bcamp1973
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 04 August 2006 - 08:20 PM

i want to force users to create passwords that are alpha-numeric only.  however, i'm not quite sure how to validate their entry.  i'm guessing preg_replace() is an option, but is it the best one?  Is there a built in PHP function for this? I haven't been able to find it at php.net if there is :(

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 04 August 2006 - 08:26 PM

You can use a js regular expression for this:

function checkpw(pass) {
	var m = /^[0-9a-zA-z]$/;
	if (!pass.match(m)) {
		alert("Please use only numbers and letters for your password.");
		return false;
	} else {
		return true;
	}
}

call is by using either a onsubmit on the form, or on blur on the form field:

<input type="password" name="password" size="10" onblur="checkpass(this);">


#3 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 04 August 2006 - 10:50 PM

Sorry for the intrusion, but isn't this a PHP forum?

RTFM is an almost extinct art form, it should be subsidized.

#4 Drumminxx

Drumminxx
  • Members
  • PipPipPip
  • Advanced Member
  • 92 posts
  • LocationUSA

Posted 04 August 2006 - 11:26 PM

another problem with that is if the user has javascript turned off...

here's an example using eregi which is case insensitive

<?
$s = "Ssertfrt633";

if (eregi('^[[:alnum:]]{2,}$',$s))	{
	echo 'ok';
}else{
	echo 'bad';
}

?>

:: gucci.com ::
:: blockbuster.com ::

--------------------




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users