how to check if a string only has numbers code example Example: check if string contains numbers str.matches(".*\\d.*");