podja Posted April 10, 2007 Share Posted April 10, 2007 I'm looking to validate the username for my user registration system. I only want to alow certain characters (A-Z,a-z,1-9,_,-). How do I check that the username only contains these characters? I think it is eregi or regi or something similar. Quote Link to comment Share on other sites More sharing options...
Hughesy1986 Posted April 10, 2007 Share Posted April 10, 2007 http://uk2.php.net/eregi Quote Link to comment Share on other sites More sharing options...
Lumio Posted April 12, 2007 Share Posted April 12, 2007 <?php $username = 'test5-3_4'; if (preg_match('{^[\w\d-]+$}', $username) ) echo 'valid'; else echo 'invalid'; ?> ^ means it has to begin from the first sign on. In my example from t \w is the same as A-Za-z_ \d is the same as 0-9 $ means it has to be the last sign... so test5-3_4 & is invalid Quote Link to comment Share on other sites More sharing options...
neel_basu Posted April 15, 2007 Share Posted April 15, 2007 Use \w+ 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.