boney alex Posted April 26, 2007 Share Posted April 26, 2007 Ive got this function which checks the username contains only letters and numbers and is between 6-12 characters long. How do I change this function to only allow letters and spaces and be of any length? <? function usernamecheck($username) { if (eregi ("^[[:alnum:]]{6,12}$", $username)) { return true; } else { return false; } } ?> Cheers Quote Link to comment https://forums.phpfreaks.com/topic/48789-solved-easy-question/ Share on other sites More sharing options...
KevinM1 Posted April 26, 2007 Share Posted April 26, 2007 Ive got this function which checks the username contains only letters and numbers and is between 6-12 characters long. How do I change this function to only allow letters and spaces and be of any length? <? function usernamecheck($username) { if (eregi ("^[[:alnum:]]{6,12}$", $username)) { return true; } else { return false; } } ?> Cheers Try something like: <?php function usernamecheck($username){ if(eregi("^[a-zA-Z ]*$", $username)){ return true; } else{ return false; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/48789-solved-easy-question/#findComment-239160 Share on other sites More sharing options...
Psycho Posted April 26, 2007 Share Posted April 26, 2007 You should probably "trim" the value to remove leading and trailing spaces though. Also, do you want to allow consecutive spaces? If not, you can create a regex for that. Quote Link to comment https://forums.phpfreaks.com/topic/48789-solved-easy-question/#findComment-239198 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.