How can I validate user input contain only 5 digits with 2 decimal. I am using below code to check 5 digits, but how to check 2 decimal.
if (!id.equals("")) {
try {
Integer.parseInt(id);
if (id.length() <= 5) {
return true;
}
} catch (NumberFormatException nfe) {
return false;
}
}
The DecimalFormat class will help you significantly with this. You can check that the user-input can be parsed according to a specific pattern.
The commons-validator library wraps this up in a convenient method call.
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