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. Link to comment https://forums.phpfreaks.com/topic/46400-eregi-or-regi/ Share on other sites More sharing options...
Hughesy1986 Posted April 10, 2007 Share Posted April 10, 2007 http://uk2.php.net/eregi Link to comment https://forums.phpfreaks.com/topic/46400-eregi-or-regi/#findComment-225696 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 Link to comment https://forums.phpfreaks.com/topic/46400-eregi-or-regi/#findComment-227427 Share on other sites More sharing options...
neel_basu Posted April 15, 2007 Share Posted April 15, 2007 Use \w+ Link to comment https://forums.phpfreaks.com/topic/46400-eregi-or-regi/#findComment-229603 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.