Positive number match with regular expression in java

Posted on 2010-09-17
Medium Priority
Last Modified: 2012-05-10
Hi There,

I am trying to match ONLY positive number of type Double with a regular expression in Java.

any clues?

Question by:theartha
  • 3
LVL 86

Accepted Solution

CEHJ earned 2000 total points
ID: 33703194
Try matching the following:
	final String NO_NEG = "(?<!-)\\d*\\.\\d+";

Open in new window


Author Comment

ID: 33703260

How to compare that NO_NEG string with my input value.?

Pattern pattern = Pattern.compile(NO_NEG);
Matcher matcher1 = pattern.matcher(amount);  
matcher1.matches()== true{
//do something

Error: The method matcher(CharSequence) in the type Pattern is not applicable for the arguments
LVL 86

Expert Comment

ID: 33703314
boolean ok = amount.matches(NO_NEG);

Open in new window

LVL 86

Expert Comment

ID: 33703396

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

587 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