Can we restrict user to enter only alphanumeric ch...
# compose
a
Can we restrict user to enter only alphanumeric chars in BasicTextField. E.g. we can do this in xml as follows ->
Copy code
android:digits="abcdefghijklmnopqrstuvwxyz1234567890 "
f
You hold the state so you can enforce the rules you need yourself. In other words, don't let the state change into something you don't wont it to be in
onValueChange
callback.
1
a
got it, thanks
Done
Copy code
onValueChange = {
    if (it.matches("^[a-zA-Z0-9@.]*$".toRegex()))
        onValueChange(it)
}
🎉 7