+117 votes
277 views
How to check given string only have numbers using java?
in Programming by (1.1k points) | 277 views

Please log in or register to answer this question.

1 Answer

+109 votes

By Using Regular Expression:

  • Get the String.
  • Create a Regular Expression to check string contains only digits as mentioned here: regex = "[0-9]+";
  • Match the given string with Regular Expression
  • Return true if the string matches with the given regular expression, else return false.
by (1.0k points)