I want to set EditText validation,
Only contains number, size 4 digit for decimal, and 2 digit for fraction value..total 6 digit,
I also want just enter only number form number pad. if i am select any non numeric number then EditText will not accept it.
if any suggestion, it would be great. Thanks.
Have
android:inputType="numberDecimal"
attribute for EditText
You can use a regex for the validation part. The below is only a sample
You can check with a online regex tester @ http://regex101.com/r/uG9aF6/1
String input = "1024.22";
String pattern = "([0-9]{4})(\.)([0-2]{2})"; // 4 digits followe by . followed by 2 digits
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(input);
if(m.matches())
{
System.out.println("Validated");
}
else
{
System.out.println("Not Validated");
}
android:inputType ="number"
and android:maxLength="6"
in xml layout of editText
will popup the keypad of digits and only six digits can be entered in the editText
like this
<EditText
android:id="@+id/myinput"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:maxLength="6"
android:hint="@string/somestring"
android:layout_weight="1"
/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With