Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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"
like image 706
Brinda K Avatar asked Feb 12 '14 10:02

Brinda K


1 Answers

Try this:

android:inputType="number|none"
android:maxLength="3"
android:digits="0123456789"
like image 56
SMR Avatar answered Sep 30 '22 09:09

SMR