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
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]
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.