Jump to content

Username validation


Kryptix

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/258506-username-validation/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/258506-username-validation/#findComment-1325118
Share on other sites

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!

Link to comment
https://forums.phpfreaks.com/topic/258506-username-validation/#findComment-1325175
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.