0

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) });
ale
  • 3,301
  • 10
  • 40
  • 48

1 Answers1

2

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}.

Ωmega
  • 42,614
  • 34
  • 134
  • 203
  • how can set the EditText to you regex? How is the sintax – ale Nov 19 '12 at 21:45
  • @ale : http://stackoverflow.com/questions/4180770/allow-only-selected-charcters-based-on-regex-in-an-edittext : PATTERN syntax is `/pattern/` – Ωmega Nov 19 '12 at 21:48