0 votes
138 views
How to check given string only have numbers using java?
in Programming by (354 points) | 138 views

Please log in or register to answer this question.

1 Answer

0 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 (256 points)