Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

trouble with regex

 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i found it out:
should be:

[ August 23, 2005: Message edited by: miguel lisboa ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic