Positive number match with regular expression in java

Hi There,

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

any clues?

Thanks.
thearthaAsked:
Who is Participating?
 
CEHJConnect With a Mentor Commented:
Try matching the following:
	final String NO_NEG = "(?<!-)\\d*\\.\\d+";

Open in new window

0
 
thearthaAuthor Commented:
@CEHJ:

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

i.e
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
 (Double)
0
 
CEHJCommented:
Simply
boolean ok = amount.matches(NO_NEG);

Open in new window

0
 
CEHJCommented:
:-)
0
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.

All Courses

From novice to tech pro — start learning today.