Venkatesh S
Venkatesh S

Reputation: 5492

While Entering Numerical Values in Edittext how to check for Pattern ##.### whille Typing

mPattern = Pattern.compile("([1-9]{1}[0-9]{0,2}([0-9]{3})*(\\.[0-9]{0,2})?
                            |[1-9]{1}[0-9]{0,}(\\.[0-9]{0,2})?|0(\\.[0-9]{0,2})? 
                            |(\\.[0-9]{1,2})?)");

above is the pattern but its not properly checking the values in edittext while entering the value.

can anyone help me

to validate inputs like this

12.325
95.365
85.665
87.256

Upvotes: 1

Views: 169

Answers (1)

Keppil
Keppil

Reputation: 46219

From what I can tell from your regex, you want to allow 1-3 digits, followed by an optional . followed by 1-3 digits. Also, you seem to want to allow the forms 0.##, and .###. This validates those specifications:

mPattern = Pattern.compile("[1-9][0-9]{0,2}(\\.[0-9]{1,3})?|0?\\.[0-9]{1,3}");

Upvotes: 1

Related Questions