jeudi 18 octobre 2018

Regex (HTML input pattern) for username

I don't quite understand how to put a regex expression together. I keep trying to combine stuff from similar threads I've seen here, with stuff I've been googling, but I seem to be doing this all wrong.

The only thing I can get right is

[A-Za-z0-9]{6,20}

But when I try to add more to the pattern, it doesn't seem to be working.

NOTE This is using the HTML input pattern attribute. I would appreciate some assistance on this, but I would also appreciate if someone could break down the solution for me, so I could comprehend it a little better.

  • Username can contain uppercase/lowercase letters
  • Username can contain numbers
  • Username can contain underscore, hyphen or period
  • Username cannot contain spaces
  • Username cannot contain special characters
  • Username should be between 6-20 characters in length

I've tried something like this:

[A-Za-z0-9_-]{6,20}\S

I feel like I'm sort of there, but not quite there.

Aucun commentaire:

Enregistrer un commentaire