Skip to content

Commit

Permalink
GBS-55 | The size conversation resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
MenekseYuncu committed Oct 27, 2024
1 parent 77524e1 commit 050447b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public class RegisterRequest {

@NotBlank
@Username
@Size(min = 3, max = 20)
private String username;

@NotBlank
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class UsernameValidator implements ConstraintValidator<Username, String> {

private static final String USERNAME_REGEX = "^[a-zA-Z0-9]$";
private static final String USERNAME_REGEX = "^[a-zA-Z0-9]{3,20}$";

@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
Expand All @@ -23,6 +23,13 @@ public boolean isValid(String value, ConstraintValidatorContext context) {
return false;
}

if (value.length() <= 3 || value.length() >= 20) {
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate("Username must be between 3 and 20 characters long")
.addConstraintViolation();
return false;
}

if (!lowerCasedValue.matches(USERNAME_REGEX)) {
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate("Username must be alphanumeric")
Expand Down

0 comments on commit 050447b

Please sign in to comment.