Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading