Skip to content

Instantly share code, notes, and snippets.

@adrianhall
Created April 10, 2018 15:27
Show Gist options
  • Save adrianhall/d2ab5d93bfc45e6d19a38da0391e5650 to your computer and use it in GitHub Desktop.
Save adrianhall/d2ab5d93bfc45e6d19a38da0391e5650 to your computer and use it in GitHub Desktop.
Extension function for a validator
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