Thursday, October 25, 2012

Check if inputTextField contains numbers only

Many times you want to check if the inputText contains numbers of decimals only e.g. getting amount in input.


public boolean isValidNumber(String inputNumber){
     Pattern p = Pattern.compile('\\d+(\\.\\d+)?');
     Matcher m =p.matcher(inputNumber);
     return m.Matches();
}

The above method return true if it is a valid number else return false.

No comments:

Post a Comment