I need set max input of integer (7), and max inut of decimal (2). Example: 7777777.77, at this moment I' using Regex for integer, but how can I set input user for decimal??
editText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(7) });
Basic regex pattern would be
^[0-9]{1,7}([.][0-9]{1,2})?$
However if your regex engine supports negative lookahead and you want to prevent unwanted leading zeros, such as 000123.45
, then use pattern
^(?!0[0-9])[0-9]{1,7}([.][0-9]{1,2})?$
And if you want to allow numbers with decimal point and no traling numbers, such as 123.
, then replace {1,2}
part with {0,2}
.