Kryptix Posted March 8, 2012 Share Posted March 8, 2012 Hi, I have this JavaScript/jQuery regex: var username_regex = /^[A-Za-z0-9 ]{2,12}$/; It's perfect except: I want it to return false if the username starts or ends with a space. I want it to turn false if there's more than 1 space in a row. Can anyone help me please? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/258506-username-validation/ Share on other sites More sharing options...
requinix Posted March 8, 2012 Share Posted March 8, 2012 Start with any number of non-space characters, then repeat a set of one space followed by more non-spaces. Problem is that it's harder to do the 2-12 requirement. /^[a-z0-9]+( [a-z0-9]+)*$/i For the length just do x.length>=2 and x.length Quote Link to comment https://forums.phpfreaks.com/topic/258506-username-validation/#findComment-1325118 Share on other sites More sharing options...
Kryptix Posted March 8, 2012 Author Share Posted March 8, 2012 Start with any number of non-space characters, then repeat a set of one space followed by more non-spaces. Problem is that it's harder to do the 2-12 requirement. /^[a-z0-9]+( [a-z0-9]+)*$/i For the length just do x.length>=2 and x.length<=12. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/258506-username-validation/#findComment-1325175 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.