I am wondering how I can check if a user\'s input is a certain primitive type (I mean integer, String, etc... I think it\'s called primitive type?). I want a user to input s
You may try this with Regex:
String input = "34"; if(input.matches("^\\d+(\\.\\d+)?")) { //okay } else { // not okay ! }
Here,
^\\d+ says that input starts with a digit 0-9,
^\\d+
()? may/or may not occur
()?
\\. allows one period in input
\\.