java - Expression to validate the required field -


below method throw exception if amount not integer or float when pass string forcefully not work , in case of string should throw exception , make valid false still return valid true please advise wrong in expression below

private boolean isamount(string amount) {     boolean isvalid = true;     try {         if (amount.matches("[-+]?[0-9]*\\.?[0-9]+"))  {             return isvalid;              }     }     catch (numberformatexception e) {         isvalid = false;     }     return isvalid; } 

you not trying convert anywhere, no exception thrown. this...

private boolean isamount(string amount) {     return amount.matches("[-+]?[0-9]*\\.?[0-9]+")); } 

Comments