override fun afterTextChanged(s: Editable?) { afterTextChanged.invoke(s.toString()) } override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { } override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { } }) } fun EditText.validate(validator: (String) -> Boolean, message: String, errorCallback: () -> Unit) { this.afterTextChanged { this.error = if (validator(it)) null else message } this.error = if (validator(this.text.toString())) null else message if (this.error.isNotEmpty()) { errorCallback.invoke() } }