From 02e7a05e5c811ea625d819dbe52a5cd6cb160266 Mon Sep 17 00:00:00 2001 From: LEE YOU BIN Date: Thu, 11 Jul 2024 07:43:30 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT/#14]=20=EA=B8=80=EC=9E=90=EC=88=98=20?= =?UTF-8?q?=EC=A0=9C=ED=95=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../feature/onboarding/signup/SignUpViewModel.kt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/feature/src/main/java/com/terning/feature/onboarding/signup/SignUpViewModel.kt b/feature/src/main/java/com/terning/feature/onboarding/signup/SignUpViewModel.kt index 1fc7b8a59..1afd647bb 100644 --- a/feature/src/main/java/com/terning/feature/onboarding/signup/SignUpViewModel.kt +++ b/feature/src/main/java/com/terning/feature/onboarding/signup/SignUpViewModel.kt @@ -20,10 +20,11 @@ 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, @@ -31,8 +32,8 @@ class SignUpViewModel @Inject constructor() : ViewModel() { 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, @@ -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, @@ -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 = "이용 가능한 이름이에요" }