Skip to content

Instantly share code, notes, and snippets.

@adrianhall
Created April 10, 2018 15:19
Show Gist options
  • Save adrianhall/3cf7f28d6a73cba193c59cad2d98c35b to your computer and use it in GitHub Desktop.
Save adrianhall/3cf7f28d6a73cba193c59cad2d98c35b to your computer and use it in GitHub Desktop.
Potential Kotlin code for content validation.
field.addTextChangeListener(object: TextWatcher {
override fun afterTextChanged(s: Editable?) {
val content = s?.text.toString()
s?.error = if (content.length >= 6) null else "Minimum length = 6"
}
override fun beforeTextChanged(s: Editable?) { }
override fun onTextChanged(s: Editable?) { }
})
field.error = if (field.text.toString().length >= 6) null else "Minimum length = 6"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment