Skip to content

Instantly share code, notes, and snippets.

@japharr
Created January 22, 2022 01:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save japharr/afb97f5830933e46cca7651196e2b3fe to your computer and use it in GitHub Desktop.
Save japharr/afb97f5830933e46cca7651196e2b3fe to your computer and use it in GitHub Desktop.
Username regex
^(?=.{8,20}$)(?![_.])(?!.*[_.]{2})[a-zA-Z0-9._]+(?<![_.])$
^(?=.{8,20}$)(?![_.])(?!.*[_.]{2})[a-zA-Z0-9._]+(?<![_.])$
└─────┬────┘└───┬──┘└─────┬─────┘└─────┬─────┘ └───┬───┘
│ │ │ │ no _ or . at the end
│ │ │ │
│ │ │ allowed characters
│ │ │
│ │ no __ or _. or ._ or .. inside
│ │
│ no _ or . at the beginning
username is 8-20 characters long
If your browser raises an error due to lack of negative look-behind support, use the following alternative pattern:
^(?=[a-zA-Z0-9._]{8,20}$)(?!.*[_.]{2})[^_.].*[^_.]$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment