Created
April 10, 2018 15:27
-
-
Save adrianhall/d2ab5d93bfc45e6d19a38da0391e5650 to your computer and use it in GitHub Desktop.
Extension function for a validator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun EditText.validate(validator: (String) -> Boolean, message: String) { | |
this.afterTextChanged { | |
this.error = if (validator(it)) null else message | |
} | |
this.error = if (validator(this.text.toString())) null else message | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment