Regular expression for InputFilter for EditText in Android

I need to implement an input filter to limit the input of numbers in a format 1234.35. That is, a maximum of four before .and two decimal places. I use this regex pattern :

Pattern.compile("[0-9]{0,4}+((\\.[0-9]{0,2})?)||(\\.)?");

This works, but as soon as I enter the number in the edit text and try to change the values ​​before the decimals, I cannot edit them. I can delete them only.

What's wrong?

+3
source share
1 answer

Based on what you said, and I think it looks like what you were trying to do, I would use this regex:

^(\d{0,4})(\.\d{1,2})?$

"0-4 " " ", . , . : 5, 1234, 1234.56, .2 .31 , .123, 1234., 1234.567, 12345 . .

, , (, ., 1234. ..), :

^(\d{0,4})(\.(\d{1,2})?)?$
+2

All Articles