Amount validation - regular expression in Java -


in java class need regular expression amount validation following conditions:

  1. maximum price 9999.99
  2. minimum amount 1
  3. 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

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -