My suggestion would be display an error while the value inserted is invalid. For instance:
fun isValidEmail(emailStr: String?) =
Pattern
.compile(
"^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$",
Pattern.CASE_INSENSITIVE
).matcher(emailStr).find()
...
var emailText by remember { mutableStateOf("") }
var showError by remember { mutableStateOf(false) }
TextField(
value = emailText,
onValueChange = {
emailText = it
showError = !isValidEmail(it)
},
isErrorValue = showError,
label = { Text(text = "Email") },
modifier = Modifier.fillMaxWidth()
)
if (showError) {
Text("Email is invalid")
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…