ballouta Posted May 20, 2009 Share Posted May 20, 2009 Hello I have this expression to validate the username before registration: <?php if(!preg_match("!^[a-z0-9_~]{1,30}$!i", $uname)) { echo "You have entered an invalid username."; } ?> It is very important for me that -spaces are not allowed -usernames can be only letters or numbers or alphanumeric no special signs (# % & $ @ etc..) does my expression do all this?! Many thanks Link to comment https://forums.phpfreaks.com/topic/158876-solved-validating-username/ Share on other sites More sharing options...
waynew Posted May 20, 2009 Share Posted May 20, 2009 This works just fine for me: I've taken the min and max lengths out so that you can see where they're placed. $min_length = 1; $max_length = 10; if(!eregi("^[a-zA-Z0-9]{".$min_length.",".$max_length."}$",$username)){ //invalid } Link to comment https://forums.phpfreaks.com/topic/158876-solved-validating-username/#findComment-837968 Share on other sites More sharing options...
ballouta Posted May 20, 2009 Author Share Posted May 20, 2009 Thank you Link to comment https://forums.phpfreaks.com/topic/158876-solved-validating-username/#findComment-837972 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.