Question: how to check if a string contains only numbers in java using regex?
Answer: String regex = "\\d+"; As per Java regular expressions, the + means "one or more times" and \d means "a digit".