harchew Posted February 22, 2008 Share Posted February 22, 2008 How do I validate an user name in such a way that, it must contain at least an alpha and number. Only alpha,number and ._ are allow for the user name otherwise return invalid. Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 22, 2008 Share Posted February 22, 2008 you would use regular expresions, i believe there is another forum specifically for these questions: http://www.phpfreaks.com/forums/index.php/board,43.0.html ---- im not so good with regex in php but you could do: <?php $string = "USER._NAME23"; // ex valid username if(preg_match("/[^a-zA-Z0-9\._]/i",$string) == 0){ // valid characters if(preg_match("/[0-9]/i",$string) == 0){ // No Numbers Found echo("Username must contain at least 1 number"); } if(preg_match("/[a-z]/i",$string) == 0){ // No Letters Found echo("Username must contain at least 1 character"); } $strlen = strlen($string); if($strlen < 8 && $strlen > 16){ echo("Username must be between 8 and 16 characters in length"); } }else{ echo("You have illegal characters in your username, Legal characters include: A-Z, 0-9, a period (.), and an underscore ( _ )"); } ?> hope this helps, Quote Link to comment Share on other sites More sharing options...
harchew Posted February 22, 2008 Author Share Posted February 22, 2008 Its working perfectly. Thank you so much (Bow...) 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.