Class CreateUserValidator
java.lang.Object
com.app.validate.CreateUserValidator
- All Implemented Interfaces:
Validator<CreateUserDto>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
validate
(CreateUserDto createUserDto) Validates the CreateUserDto object by checking: - Whether the DTO is null
-
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 namesurnameRegex
- regex pattern for validating the user's surnameusernameRegex
- regex pattern for validating the usernamepasswordRegex
- list of regex patterns for validating passwordsemailRegex
- regex pattern for validating email formatminAge
- minimum allowed age for the userpasswordMinLength
- minimum length required for the password
-
-
Method Details
-
validate
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 interfaceValidator<CreateUserDto>
- Parameters:
createUserDto
- the DTO containing user data to validate- Throws:
ValidationException
- if any validation errors are found
-