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!! 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 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 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. Link to comment https://forums.phpfreaks.com/topic/207992-validating-alphanumeric-password/#findComment-1087462 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.