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

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -