Search code examples
javastringcharint

Check if String doesn't have any letters but only numbers


How can I check if a String in java has no letters, only numbers? Thank you for the answer


Solution

  • You can use regex: yourString.matches("\\d+")

    \\d means one digit 0-9, + means one or more, combined \\d+ is equal to one or more digit :)