validateUsername = function (username) {
  var usernameRegex = /^(?=[\w.-]+$)(?!.*[._-]{2})(?!\.)(?!.*\.$).{3,34}$/;
  return (
    this.provider !== 'local' ||
    (username && usernameRegex.test(username) && config.illegalUsernames.indexOf(username) < 0)
  );
}
A Validation function for username
- at least 3 characters
- only a-z0-9_-.
- contain at least one alphanumeric character
- not in list of illegal usernames
- no consecutive dots: "." ok, ".." nope
- not begin or end with "."