천천히 , 강하게 멀리

코틀린 유효성 검사 본문

Programming/Kotlin

코틀린 유효성 검사

힌새 2020. 3. 26. 13:56

//이메일 유효성

if (!Patterns.EMAIL_ADDRESS.matcher(editEmail.text.toString()).matches()) {
    Toast.makeText(this, "이메일 형식이 아닙니다", Toast.LENGTH_SHORT).show()
    editEmail.requestFocus()
}

 

// 비밀번호 유효성

 

val passMatches = Regex("^(?=.*[a-zA-Z0-9])(?=.*[!@#\$%^*+=-]).{8,20}$")

if (!editPassword.text.toString().matches(passMatches)){
    Toast.makeText(this, "올바른 비밀번호가 아닙니다.", Toast.LENGTH_SHORT).show()
    editPassword.requestFocus()
}

 

//핸드폰번호 유효성

val phoneMatches = Regex("^01[016789][0-9]{3,4}[0-9]{4}$")

if (!editPhone_number.text.toString().matches(phoneMatches)) {
    Toast.makeText(this, "올바른 핸드폰 번호가 아닙니다.", Toast.LENGTH_SHORT).show()
    editPhone_number.requestFocus()
}

 

'Programming > Kotlin' 카테고리의 다른 글

SharedPreference 사용하는 방법.  (0) 2020.04.23