Skip to content

Commit

Permalink
fix: 정규식 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
EunhoKang committed Nov 15, 2023
1 parent 9208192 commit e6d92cd
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow

class LoginViewModel : ViewModel() {
private val emailPattern = """^[\w.+-]+@((?!-)[A-Za-z0-9-]{1,63}(?<!-)\.)+[A-Za-z]{2,6}$""".toRegex()
private val passwordPattern = """^(?=[A-Za-z\d!@#$%^&*]*\d)(?=[A-Za-z\d!@#$%^&*]*[a-z])(?=[A-Za-z\d!@#$%^&*]*[A-Z])(?=[A-Za-z\d!@#$%^&*]*[!@#$%^&*])[A-Za-z\d!@#$%^&*]{8,16}$""".toRegex()

data class State(
val email: String = "",
val password: String = ""
Expand All @@ -23,12 +26,14 @@ class LoginViewModel : ViewModel() {
}

fun logIn(onSuccess: (Unit) -> Unit) {
val emailPattern = Regex("""^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}${'$'}""")
val passwordPattern = Regex("""(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#${'$'}%^&*]).{8,16}""")
if (emailPattern.matches(_state.value.email) && passwordPattern.matches(_state.value.password)) {
if (checkEmailAndPassword()) {
// TODO: 서버에 정보 전송
} else {
onSuccess.invoke(Unit)
}
}

private fun checkEmailAndPassword(): Boolean {
return emailPattern.matches(_state.value.email) && passwordPattern.matches(_state.value.password)
}
}

0 comments on commit e6d92cd

Please sign in to comment.