I’m trying to create a regular expression to validate usernames against these criteria:
- Only contains alphanumeric characters,
underscore and dot. - Underscore and dot can’t be at the end or
start of a username (e.g_username/username_/.username/username.). - Underscore and dot can’t be next to each other (e.g
user_.name). - Underscore or dot can’t be used multiple times in a row (e.g
user__name/user..name). - Number of characters must be between 8 to 20.
This is what I’ve done so far; it sounds it enforces all criteria rules but the 5th rule. I don’t know how to add the 5th rule to this:
^[a-zA-Z0-9]+([._]?[a-zA-Z0-9]+)*$
If your browser raises an error due to lack of negative look-behind support, use the following alternative pattern: