示例#1
0
        private void ValidateUsername(string username)
        {
            if (repository.GetAccountByUsername(username) != null)
            { // Username already exists in the database.
                throw new ValidationException("Username already exists!");
            }

            if (TextValidator.IsNullEmptyOrWhiteSpace(username))
            { // Username empty or not provided.
                throw new ValidationException("Username can't be empty!");
            }

            if (!TextValidator.ContainsBetweenXAndYCharacters(username, 8, 32))
            { // Username doesn't contain between 8 and 32 characters.
                throw new ValidationException("Username must contain between 8 and 32 characters!");
            }

            if (!TextValidator.ContainsLetters(username))
            {  // Username doesn't contain any letters (only numbers or symbols).
                throw new ValidationException("Username must contain at least one letter!");
            }
        }