NewPartizal
NewPartizal

Reputation: 1124

How to force EditText to accept only numbers in compose kotlin?

How to force outLineTxtFieldValue to accept only numbers ?.

For example,

user can only enter numbers, not a negative value. We can enter numbers such as

120, 1, 9, 10012,

in short, we can say positive integers or natural numbers in kotlin compose outlinetextfield or textfield

Upvotes: 0

Views: 1253

Answers (2)

skafle
skafle

Reputation: 1025

Simply display the keyboard with only numbers:

TextField(
     value = textState,
     onValueChange = { text ->
         textState = text
     },
     keyboardOptions = KeyboardOptions.Default.copy(
         keyboardType = KeyboardType.NumberPassword
     ),
     visualTransformation = VisualTransformation.None
)

Upvotes: 0

Samsad CV
Samsad CV

Reputation: 125

TextField(
    keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number)

Upvotes: 1

Related Questions