Skip to content

Commit

Permalink
bugfix: added allowed symbols to nickname validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Troha7 committed Jan 8, 2024
1 parent ef2086d commit 7ccac22
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

public class NicknameValidator implements ConstraintValidator<NicknameValidation, String> {

private static final Pattern NICKNAME_PATTERN = Pattern.compile("^[a-zA-Z0-9а-яА-ЯІіЇї]{4,20}$");
private static final Pattern NICKNAME_PATTERN = Pattern.compile(
"^[a-zA-Z0-9а-яА-ЯІіЇї!@#$%^&*_\\-+=~?]{4,20}$");

@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
Expand All @@ -23,13 +24,15 @@ public boolean isValid(String value, ConstraintValidatorContext context) {
return false;
} else if (!NICKNAME_PATTERN.matcher(value).matches()) {
context
.buildConstraintViolationWithTemplate("The nickname is invalid")
.buildConstraintViolationWithTemplate(
"The nickname should be 4-20 characters long and include only letters, numbers or "
+ "symbols [! @ # $ % ^ & * _ - + = ~ ?]")
.addConstraintViolation();
return false;
} else if (PATTERN_SPACE.matcher(value).matches()) {
context
.buildConstraintViolationWithTemplate("The nickname should not include space")
.addConstraintViolation();
.buildConstraintViolationWithTemplate("The nickname should not include space")
.addConstraintViolation();
return false;
}

Expand Down

0 comments on commit 7ccac22

Please sign in to comment.