Jump to content

validating alpha-numeric password


bcamp1973

Recommended Posts

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 :(
Link to comment
https://forums.phpfreaks.com/topic/16585-validating-alpha-numeric-password/
Share on other sites

You can use a js regular expression for this:

[code]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;
}
}[/code]

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.