[Last Call] Learn how to a build a cloud-first strategyRegister Now


Validation method

Posted on 2005-04-20
Medium Priority
Last Modified: 2010-03-31
I need help writing a method that determines if all the characters in a passed string are numbers.

method skeleton :
public boolean isNumeric (String field){
  boolean isValid;
  //determine if string all numbers
 //if string all numbers isValid = true;
 //else isValid = false;
 return isValid;


Please help.
Question by:apparition
  • 2
  • 2
LVL 86

Accepted Solution

CEHJ earned 600 total points
ID: 13826971
boolean valid = field.matches("\\d+");
LVL 25

Expert Comment

ID: 13827035
full points to CEHJ, but this would be a more efficient method to perform this, I imagine:

public boolean isNumeric( String field )
    return field.matched( "\\d+" );               // No idea how this works, but you're the man CEHJ
LVL 25

Expert Comment

ID: 13827039

     return field.matches( "\\d+" );

LVL 86

Expert Comment

ID: 13827079

Expert Comment

ID: 14573940
It is all about patterns, regular expression etc.

d indicates a digit ( 0 to 9)
+ indicates one or more.

So, matches method returns true if the field has one or more digits and nothing else. Otherwise it will return false.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question