Skip to content

Commit 050447b

Browse files
committed
GBS-55 | The size conversation resolved
1 parent 77524e1 commit 050447b

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/main/java/org/gelecekbilimde/scienceplatform/auth/model/request/RegisterRequest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public class RegisterRequest {
3131

3232
@NotBlank
3333
@Username
34-
@Size(min = 3, max = 20)
3534
private String username;
3635

3736
@NotBlank

src/main/java/org/gelecekbilimde/scienceplatform/common/util/validation/UsernameValidator.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class UsernameValidator implements ConstraintValidator<Username, String> {
88

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

1111
@Override
1212
public boolean isValid(String value, ConstraintValidatorContext context) {
@@ -23,6 +23,13 @@ public boolean isValid(String value, ConstraintValidatorContext context) {
2323
return false;
2424
}
2525

26+
if (value.length() <= 3 || value.length() >= 20) {
27+
context.disableDefaultConstraintViolation();
28+
context.buildConstraintViolationWithTemplate("Username must be between 3 and 20 characters long")
29+
.addConstraintViolation();
30+
return false;
31+
}
32+
2633
if (!lowerCasedValue.matches(USERNAME_REGEX)) {
2734
context.disableDefaultConstraintViolation();
2835
context.buildConstraintViolationWithTemplate("Username must be alphanumeric")

0 commit comments

Comments
 (0)