Code (Took from this stackoverflow):
String reg = "^['$']([0-9]{1,3})(?:,?[0-9]{3})*\\.[0-9]{2}$";
String input = "$123,213,123.00"; //Valid input
Pattern pattern = Pattern.compile(reg);
Matcher matcher = pattern.matcher(input);
if (matcher.find()) {
System.out.println(matcher.group(0)); //prints /{item}/
} else {
System.out.println("Match not found");
}
Issue : Even if I keep the input as $1234,213,123.00
(4 digits in the beginning), the code takes it as a valid value. But in this case, I want the code to say "Match not found". Please check the regex.