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

x
?
Solved

Validation method

Posted on 2005-04-20
5
Medium Priority
?
207 Views
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.
0
Comment
Question by:apparition
  • 2
  • 2
5 Comments
 
LVL 86

Accepted Solution

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

Expert Comment

by:InteractiveMind
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
}
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13827039
*Sorry:

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

instead
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13827079
:-)
0
 
LVL 3

Expert Comment

by:unshetty
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.
0

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