How do you set EditText to only accept numbers without decimals in Android?
android, java, regex
Solution
Try this:
android:inputType="number|none"
android:maxLength="3"
android:digits="0123456789"
Problem
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" ```