I've never used regex before, but this java function requires it (shown here: How to set Edittext view allow only two numeric values and two decimal values like ##.##)
I basically just need to get a float from it the text box, should be simple. I used a tool and it said this should work:
String re1="([+-]?\\d*\\.\\d+)(?![-+0-9\\.])";
But it doesn't seem to be working, it doesn't let me put anything in the text box.
What's the right way to do this? Thanks
Try this:
String re1="^([+-]?\\d*\\.?\\d*)$";
The right way for this problem isn't to use a regex, but just to use:
try {
Float.parseFloat(string)
return true;
}
catch (NumberFormatException ex) {
return false;
}
Works perfectly fine, is the same code that is later used to parse the float and therefore bug free (or if it isn't we have a much bigger problem at hand).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With