Провожу валидацию бинов. Не смотря на ввод правильного формата получаю ошибки. При проверки на регулярки с самой IDEA, я получаю првильный формат, проверка внизу со скринами.
Сравнения происходят с таким алгоритмом.
if (!(regEx.matches(fieldValue.toString()))) {
validationConstraints.add(errorMessage +" -> the value is: "+fieldValue.toString());
}
Внутри бина аннотации:
@NotEmptyFieldValidation(message = "User first name field can't be empty!")
@LengthValidation(min = 3,max = 20,message = "First name need to be 3 - 20 characters!")
private String firstName;
@NotEmptyFieldValidation(message = "User last name field can't be empty!")
@LengthValidation(min = 3,max = 20,message = "Last name need to be 3 - 20 characters!")
private String lastName;
@NotEmptyFieldValidation(message = "User password field can't be empty!")
@PasswordFormatValidation(regEx = "((?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{6,20})", message = "User wrong password format! Valid combination is 6 to 20 characters string with at least one digit, one upper case letter, one lower case letter and one special symbol (“@#$%”).")
private String password;
@NotEmptyFieldValidation(message = "User type field can't be empty!")
@EmailFormatValidation(message = "User wrong email format! Valid characters are: A-Z big character with a-z small character with '.' and '0-9', then after '@' A-Z or a-z with '.', and then a-z small characters between 2-4 length!", regularExpression = "[A-Za-z.0-9]+@[A-Za-z.]+.[a-z]{2,4}")
private String email;
@NotEmptyFieldValidation(message = "User type field can't be empty!")
@LengthValidation(message = "The length of customer type can be only 7 - 16", min = 7, max = 16)
private String customerType;
@NotEmptyFieldValidation(message = "User name field can't be empty!")
@NickNameValidation(regEX = "^[a-z0-9_-]{3,15}$", nickNameMessage = "User name format is wrong! It must be 3 to 15 characters with any lower case character, digit or special symbol “_-” only")
private String nickName;
Вывод constraints:
User name format is wrong! It must be 3 to 15 characters with any lower case character, digit or special symbol “_-” only -> the value is: maksm99
User wrong email format! Valid characters are: A-Z big character with a-z small character with '.' and '0-9', then after '@' A-Z or a-z with '.', and then a-z small characters between 2-4 length! -> the value is: Maks.Burkov1998@gmail.com
User wrong password format! Valid combination is 6 to 20 characters string with at least one digit, one upper case letter, one lower case letter and one special symbol (“@#$%”). -> the value is: luda1Ms#
Данные которые посылаю через Postman! JSON!
{
"firstName":"maksimus",
"lastName":"burkovus",
"nickName":"maksm99",
"companyId":"0909876",
"companyName":"maksCompany",
"customerType":"company",
"email":"Maks.Burkov1998@gmail.com",
"password":"luda1Ms#"
}