Skip to content

Instantly share code, notes, and snippets.

@r6m
Created January 7, 2022 11:11
Show Gist options
  • Save r6m/4095343209e8d0c67cbd719d171cc810 to your computer and use it in GitHub Desktop.
Save r6m/4095343209e8d0c67cbd719d171cc810 to your computer and use it in GitHub Desktop.
username regex validator
# https://stackoverflow.com/a/12019115/2272992 by Awk
^(?=.{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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment