Class CreateUserValidator

java.lang.Object
com.app.validate.CreateUserValidator
All Implemented Interfaces:
Validator<CreateUserDto>

@Component public class CreateUserValidator extends Object implements Validator<CreateUserDto>
  • Constructor Details

    • CreateUserValidator

      public CreateUserValidator(@Value("${validate.regex.name}") String nameRegex, @Value("${validate.regex.surname}") String surnameRegex, @Value("${validate.regex.username}") String usernameRegex, @Value("${validate.regex.password}") List<String> passwordRegex, @Value("${validate.regex.email}") String emailRegex, @Value("${validate.min.age}") int minAge, @Value("${validate.password.min.length}") int passwordMinLength)
      Constructs a CreateUserValidator with regex patterns and validation constraints.
      Parameters:
      nameRegex - regex pattern for validating the user's name
      surnameRegex - regex pattern for validating the user's surname
      usernameRegex - regex pattern for validating the username
      passwordRegex - list of regex patterns for validating passwords
      emailRegex - regex pattern for validating email format
      minAge - minimum allowed age for the user
      passwordMinLength - minimum length required for the password
  • Method Details

    • validate

      public void validate(CreateUserDto createUserDto)
      Validates the CreateUserDto object by checking: - Whether the DTO is null. - If the name, surname, username, and email match the required regex patterns. - If the user's age is above the minimum required age. - If the password complies with password regex rules and minimum length. Collects all validation errors and throws ValidationException with all error messages joined.
      Specified by:
      validate in interface Validator<CreateUserDto>
      Parameters:
      createUserDto - the DTO containing user data to validate
      Throws:
      ValidationException - if any validation errors are found