bcamp1973 Posted August 4, 2006 Share Posted August 4, 2006 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 :( Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 4, 2006 Share Posted August 4, 2006 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] Quote Link to comment Share on other sites More sharing options...
ronverdonk Posted August 4, 2006 Share Posted August 4, 2006 Sorry for the intrusion, but isn't this a PHP forum? Quote Link to comment Share on other sites More sharing options...
Drumminxx Posted August 4, 2006 Share Posted August 4, 2006 another problem with that is if the user has javascript turned off...here's an example using eregi which is case insensitive[code]<?$s = "Ssertfrt633";if (eregi('^[[:alnum:]]{2,}$',$s)) { echo 'ok';}else{ echo 'bad';}?>[/code] 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.