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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.