In my app i am using good number of edittexts , each edit text will allow number and decmial number diiferently
Eg: edittext1 should hav : xxx.xx format
edittext2 should hav : x.xx format
edittext3 should hav : xx.xxx format
edittex4 should hav : xx.xx format
Tried using InputFilter on edit text i used below code which i got in SO
public class DecimalDigitsInputFilter implements InputFilter {
Pattern mPattern;
public DecimalDigitsInputFilter(int digitsBeforeZero,int digitsAfterZero) {
mPattern=Pattern.compile("[0-9]{0," + (digitsBeforeZero-1) + "}+((\\.[0-9]{0," + (digitsAfterZero-1) + "})?)||(\\.)?");
}
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
Matcher matcher=mPattern.matcher(dest);
if(!matcher.matches())
return "";
return null;
}
}
myText.setFilters(new InputFilter[] {new DecimalDigitsInputFilter(3,2)});
It partially solve the problem. what Iam looking is when i pass DecimalDigitsInputFilter(3,2)
user should be able to enter 3 digits and 4th letter only dot(.) should work restricting all other symbol entries and the after dot 2 decimal places.
Unable to get the correct regexp for this Any help is appreciated