Regular Expression In Android for Password Field

前端 未结 10 1112
执念已碎
执念已碎 2020-12-13 09:56

How can i validating the EditText with Regex by allowing particular characters . My condition is :

Password Rule:

  1. On

10条回答
  •  伪装坚强ぢ
    2020-12-13 10:17

    And for the Kotlin lovers :

    fun isValidPassword(password: String?) : Boolean {
       password?.let {
           val passwordPattern = "^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=])(?=\\S+$).{4,}$"
           val passwordMatcher = Regex(passwordPattern)
    
           return passwordMatcher.find(password) != null
       } ?: return false
    }
    

提交回复
热议问题