I use this code to validate the form of the username:
var nameRegex = /^(?=.{3,20}$)(?![_.])(?!.*[_.]{2})[a-zA-Z0-9._]+(?<![_.])$/;
var validUsername = usernameText.value.match(nameRegex);
if (validUsername == null) {
//Username is not valid
} else {
//Username is valid
}
It works fine is Chrome, but when I test it in Safari, both iOS and MacOS I get this error message in the console: SyntaxError: Invalid regular expression: invalid group specifier name
.
I'm pretty new to regular expressions and don't know how to modify the code to make it work in all browsers, or another solution to validate the username.