shadiadiph Posted April 13, 2009 Share Posted April 13, 2009 does anyone have a good regex for a username I have tried a few can't seem to find a suitable one. I am looking for on that allows _ . and no spaces but if the user puts a space by mistake at the start or end it is not counted as a space Link to comment https://forums.phpfreaks.com/topic/153822-solved-regex-for-username/ Share on other sites More sharing options...
MasterACE14 Posted April 13, 2009 Share Posted April 13, 2009 use trim(); to stop the space at front and end. Link to comment https://forums.phpfreaks.com/topic/153822-solved-regex-for-username/#findComment-808422 Share on other sites More sharing options...
.josh Posted April 13, 2009 Share Posted April 13, 2009 ~[\w\.]+~ Link to comment https://forums.phpfreaks.com/topic/153822-solved-regex-for-username/#findComment-808425 Share on other sites More sharing options...
shadiadiph Posted April 13, 2009 Author Share Posted April 13, 2009 mm this one ~[\w\.]+~ allows for spaces in the middle and charachters such as ! @ this one seems to work using trim /^\w+$/ but it doesn't allow . dots but not to worry. thanks MasterAce and Crayon Violent for your input Link to comment https://forums.phpfreaks.com/topic/153822-solved-regex-for-username/#findComment-808434 Share on other sites More sharing options...
.josh Posted April 13, 2009 Share Posted April 13, 2009 mm this one ~[\w\.]+~ allows for spaces in the middle and charachters such as ! @ this one seems to work using trim /^\w+$/ but it doesn't allow . dots but not to worry. thanks MasterAce and Crayon Violent for your input Actually what it does is match on any one or more letter, number or dot in the string, regardless of where in the string it is. It has the happy side-effect of what you mentioned. Sorry, I forgot about the whole ONLY have that stuff in the string. ~^[\w\.]+$~ Link to comment https://forums.phpfreaks.com/topic/153822-solved-regex-for-username/#findComment-808592 Share on other sites More sharing options...
shadiadiph Posted April 14, 2009 Author Share Posted April 14, 2009 thats ok no problem i hate regex its a regual pain Link to comment https://forums.phpfreaks.com/topic/153822-solved-regex-for-username/#findComment-809363 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.