@Test public void checkUsername_validUsernames() { assertFalse(UsernameUtil.checkUsername("abcd").isPresent()); assertFalse(UsernameUtil.checkUsername("abcdefghijklmnopqrstuvwxyz").isPresent()); assertFalse(UsernameUtil.checkUsername("ABCDEFGHIJKLMNOPQRSTUVWXYZ").isPresent()); assertFalse(UsernameUtil.checkUsername("web_head").isPresent()); assertFalse(UsernameUtil.checkUsername("Spider_Fan_1991").isPresent()); }
public static Optional<InvalidReason> checkUsername(@Nullable String value) { if (value == null) { return Optional.of(InvalidReason.TOO_SHORT); } else if (value.length() < MIN_LENGTH) { return Optional.of(InvalidReason.TOO_SHORT); } else if (value.length() > MAX_LENGTH) { return Optional.of(InvalidReason.TOO_LONG); } else if (DIGIT_START_PATTERN.matcher(value).matches()) { return Optional.of(InvalidReason.STARTS_WITH_NUMBER); } else if (!FULL_PATTERN.matcher(value).matches()) { return Optional.of(InvalidReason.INVALID_CHARACTERS); } else { return Optional.absent(); } }
UsernameUtil { public static Optional<InvalidReason> checkUsername(@Nullable String value) { if (value == null) { return Optional.of(InvalidReason.TOO_SHORT); } else if (value.length() < MIN_LENGTH) { return Optional.of(InvalidReason.TOO_SHORT); } else if (value.length() > MAX_LENGTH) { return Optional.of(InvalidReason.TOO_LONG); } else if (DIGIT_START_PATTERN.matcher(value).matches()) { return Optional.of(InvalidReason.STARTS_WITH_NUMBER); } else if (!FULL_PATTERN.matcher(value).matches()) { return Optional.of(InvalidReason.INVALID_CHARACTERS); } else { return Optional.absent(); } } }
UsernameUtil { public static Optional<InvalidReason> checkUsername(@Nullable String value) { if (value == null) { return Optional.of(InvalidReason.TOO_SHORT); } else if (value.length() < MIN_LENGTH) { return Optional.of(InvalidReason.TOO_SHORT); } else if (value.length() > MAX_LENGTH) { return Optional.of(InvalidReason.TOO_LONG); } else if (DIGIT_START_PATTERN.matcher(value).matches()) { return Optional.of(InvalidReason.STARTS_WITH_NUMBER); } else if (!FULL_PATTERN.matcher(value).matches()) { return Optional.of(InvalidReason.INVALID_CHARACTERS); } else { return Optional.absent(); } }  }
UsernameUtil { public static Optional<InvalidReason> checkUsername(@Nullable String value) { if (value == null) { return Optional.of(InvalidReason.TOO_SHORT); } else if (value.length() < MIN_LENGTH) { return Optional.of(InvalidReason.TOO_SHORT); } else if (value.length() > MAX_LENGTH) { return Optional.of(InvalidReason.TOO_LONG); } else if (DIGIT_START_PATTERN.matcher(value).matches()) { return Optional.of(InvalidReason.STARTS_WITH_NUMBER); } else if (!FULL_PATTERN.matcher(value).matches()) { return Optional.of(InvalidReason.INVALID_CHARACTERS); } else { return Optional.absent(); } }  static boolean isValidUsernameForSearch(@Nullable String value); static Optional<InvalidReason> checkUsername(@Nullable String value); @WorkerThread static @NonNull Optional<UUID> fetchUuidForUsername(@NonNull Context context, @NonNull String username); }
UsernameUtil { public static Optional<InvalidReason> checkUsername(@Nullable String value) { if (value == null) { return Optional.of(InvalidReason.TOO_SHORT); } else if (value.length() < MIN_LENGTH) { return Optional.of(InvalidReason.TOO_SHORT); } else if (value.length() > MAX_LENGTH) { return Optional.of(InvalidReason.TOO_LONG); } else if (DIGIT_START_PATTERN.matcher(value).matches()) { return Optional.of(InvalidReason.STARTS_WITH_NUMBER); } else if (!FULL_PATTERN.matcher(value).matches()) { return Optional.of(InvalidReason.INVALID_CHARACTERS); } else { return Optional.absent(); } }  static boolean isValidUsernameForSearch(@Nullable String value); static Optional<InvalidReason> checkUsername(@Nullable String value); @WorkerThread static @NonNull Optional<UUID> fetchUuidForUsername(@NonNull Context context, @NonNull String username); static final int MIN_LENGTH; static final int MAX_LENGTH; }