How do you set EditText to only accept numbers without decimals in Android?

13,396

Try this:

android:inputType="number|none"
android:maxLength="3"
android:digits="0123456789"
Share:
13,396
Brinda K
Author by

Brinda K

SOreadytohelp

Updated on July 24, 2022

Comments

  • Brinda K
    Brinda K almost 2 years

    My EditText should only accept a 3 digit number, not any other decimal numbers. I used the below regular expression to do that but this is even accepting characters like "." and "-". So how do you avoid accepting decimal values?

    Java:

    pattern=Pattern.compile("[0-9]{0,2}");
    

    XML:

    android:digits="0123456789"
    android:inputType="number"