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 :( Link to comment https://forums.phpfreaks.com/topic/16585-validating-alpha-numeric-password/ 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] Link to comment https://forums.phpfreaks.com/topic/16585-validating-alpha-numeric-password/#findComment-69431 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? Link to comment https://forums.phpfreaks.com/topic/16585-validating-alpha-numeric-password/#findComment-69506 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] Link to comment https://forums.phpfreaks.com/topic/16585-validating-alpha-numeric-password/#findComment-69525 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.