I am using this regex to validate usernames for my app. 3-20 characters, alphanumeric, and underscores. Not beginning with, or ending with an underscore and not having two consecutive underscores.
username.search(/^(?=.{3,20}$)(?![_])(?!.*[_]{2})[a-zA-Z0-9_]+(?<![_])$/)
But is is failing on iOS / safari with this error:
SyntaxError: Invalid regular expression: invalid group specifier name
How can I make this regex work in all major browsers?