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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

719 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