Amount validation - regular expression in Java -
in java class need regular expression amount validation following conditions:
- maximum price 9999.99
- minimum amount 1
- decimal values optional (paise optional) 9999 valid
i write following regular expression return false
both valid , invalid inputs.
here's example:
private static final string price_pattern = "((/d{1,4})(((//.)(/d{0,2})){0,1}))"; public pricecheck() { pattern = pattern.compile(price_pattern); } public boolean validate(final string username) { matcher = pattern.matcher(username); return matcher.matches(); // return false; }
use expression instead:
private static final string price_pattern = "((\\d{1,4})(((\\.)(\\d{0,2})){0,1}))";
Comments
Post a Comment