cooldude832 Posted July 22, 2007 Share Posted July 22, 2007 I'm trying to do a regex that will check to make sure a user name is >5 characters and only contains numbers/alphas/underscode. Any ideas? Link to comment https://forums.phpfreaks.com/topic/61172-help-with-regex-on-a-valid-username/ Share on other sites More sharing options...
wildteen88 Posted July 22, 2007 Share Posted July 22, 2007 A simple bit of regex: <?php $username = 'c00l_Dude'; // valid //$username = 'cooldude832'; // valid //$username = 'c00l'; // Invalid //$username = 'Cool-Dude'; // Invalid if(preg_match('/^([A-Z0-9_]){5,}$/i', $username)) { echo $username . ' - Valid'; } else { echo $username . ' - Invalid'; } ?> Link to comment https://forums.phpfreaks.com/topic/61172-help-with-regex-on-a-valid-username/#findComment-304874 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.