This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes trouble with regex Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "trouble with regex" Watch "trouble with regex" New topic
Author

trouble with regex

miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i'm trying to validate this string representing money, and i want it to be like
xxxxxx
or
xxxx.n
or
xxxx.nn

so i'm using this method:
public static boolean valida(String valor)

throws NumberFormatException {

if ( valor.matches ( "[0-9] + (\\.[0-9]{1,2})" ) ) {

return true;

}

else return false;

}


but when i test, i allways get an assertion failed:


What am i doing wrong?

TiA


java amateur
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i found it out:
should be:

[ August 23, 2005: Message edited by: miguel lisboa ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: trouble with regex
 
Similar Threads
Could anyone please help me in understanding this pattern
Arrays
What is wrong with the regex?
missing return statement?
Why doesn't this match?