I want to know if it is possible to make a single regular expression that checks if a username is valid depending on these rules:
- 3 to 12 characters
- Can have uppercase and/or lowercase characters
- Can have numeric characters
- Can have ‘_’ and ‘-‘ symbols
I know how to do the above, but what I want to check in the same regex is if the username contains consecutive symbols (eg. user__name or user–name)
Is this possible or does it require 2 regex checks?
You’d be better off with two regex checks, if anything for code readability. Regexes are hard to read already, you don’t need to make it even harder on yourself by making one complicated regex instead of two simple ones.