Skip to content

Commit

Permalink
[FEAT/#14] 글자수 제한
Browse files Browse the repository at this point in the history
  • Loading branch information
leeeyubin committed Jul 10, 2024
1 parent f925bb4 commit 02e7a05
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@ class SignUpViewModel @Inject constructor() : ViewModel() {

fun isInputValid(name: String) {
val nameErrorRegex = Regex(NAME_ERROR)
val trimmedName = if (name.length > MAX_LENGTH) name.substring(0, MAX_LENGTH) else name

when {
nameErrorRegex.containsMatchIn(name) -> _state.value = _state.value.copy(
name = name,
nameErrorRegex.containsMatchIn(trimmedName) -> _state.value = _state.value.copy(
name = trimmedName,
drawLineColor = WarningRed,
helper = HELPER_ERROR,
helperIcon = R.drawable.ic_sign_up_error,
helperColor = WarningRed,
isButtonValid = false
)

name.isEmpty() -> _state.value = _state.value.copy(
name = name,
trimmedName.isEmpty() -> _state.value = _state.value.copy(
name = trimmedName,
drawLineColor = Grey500,
helper = HELPER,
helperIcon = null,
Expand All @@ -41,7 +42,7 @@ class SignUpViewModel @Inject constructor() : ViewModel() {
)

else -> _state.value = _state.value.copy(
name = name,
name = trimmedName,
drawLineColor = TerningMain,
helper = HELPER_AVAILABLE,
helperIcon = R.drawable.ic_sign_up_available,
Expand All @@ -54,6 +55,7 @@ class SignUpViewModel @Inject constructor() : ViewModel() {
companion object {
const val NAME_ERROR = "[!@#\$%^&*(),.?\":{}|<>\\[\\]\\\\/]"
const val HELPER = "12자리 이내, 문자/숫자 가능, 특수문자/기호 입력불가"
private const val MAX_LENGTH = 12
private const val HELPER_ERROR = "이름에 특수문자는 입력할 수 없어요"
private const val HELPER_AVAILABLE = "이용 가능한 이름이에요"
}
Expand Down

0 comments on commit 02e7a05

Please sign in to comment.