thecommonthread Posted July 16, 2010 Share Posted July 16, 2010 How do check if a string has only lowercase/uppercase letters and has at least one number in it? Thanks!! Quote Link to comment https://forums.phpfreaks.com/topic/207992-validating-alphanumeric-password/ Share on other sites More sharing options...
snizkorod Posted July 17, 2010 Share Posted July 17, 2010 http://php.net/manual/en/function.ctype-alnum.php Quote Link to comment https://forums.phpfreaks.com/topic/207992-validating-alphanumeric-password/#findComment-1087306 Share on other sites More sharing options...
TOA Posted July 17, 2010 Share Posted July 17, 2010 The regex section will have your answer Quote Link to comment https://forums.phpfreaks.com/topic/207992-validating-alphanumeric-password/#findComment-1087441 Share on other sites More sharing options...
.josh Posted July 17, 2010 Share Posted July 17, 2010 ctype_alnum by itself only checks that it is an alphanumeric string. It does not determine whether it has at least one number in it. if (preg_match('~^[a-z0-9]*[0-9][a-z0-9]*$~i',$subject)) { // $subject is alphanumeric and contains at least 1 number } else { // failed } OP: This code will do what you want with one caveat: Technically a string consisting of a single digit like "9" will pass. If you want to do other things like enforce a minimum/maximum length, be more specific. Quote Link to comment https://forums.phpfreaks.com/topic/207992-validating-alphanumeric-password/#findComment-1087462 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.