Kotlin Code to Validate a Confirmation of Password

Viewed 57

Need code to validate the confirmation of password, included is the validation of password field:

    private fun passwordValidate(text: String?): Boolean {
        var p = Pattern.compile("^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[@\$!%*?&])[A-Za-z\\d@\$!%*?&]{5,20}\$")
        var m = p.matcher(text)
        return m.matches()
    }

The confirm password I would guess would start of similar as follows:

    private fun confirmpasswordValidate(text: String?): Boolean {
        var p = Pattern.compile
1 Answers

I assume that you do not need any extra method to validate the confirmpassword. You should first check if the passwords are the same and if they are, then simply check the first password with your passwordValidate method.

Related