 <p>Your solution should work, because any integer will parse as a double as well. You could make it more verbose, and have <code>0</code> represent invalid <code>1</code> represent an int and <code>2</code> represent a double.</p> <pre><code>private static int isValidQuantity(String aQuantity){ int result = 0; //first try int try{ Integer.parseInt(aQuantity); result = 1; //the parse worked }catch(NumberFormatException ex){ result = 0; } if(result == 0) { //if it's not an int then try double try{ Double.parseDouble(aQuantity); result = 2; //the parse worked }catch(NumberFormatException ex){ result = 0; } } return result; } </code></pre>