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

float regexp

 
Alessandro Ilardo
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there,
I'm not an expert of regexp and I need an help.

I've got a js script which accept personal regexp to check form values.

In a field I'd allow float numers as 00.00
On the net I found this:
__floatNum = "/^((\d+(\.\d*)?)|((\d*\.)?\d+))$/";
which doesn't get the value mentioned above.

Any helps are welcome.
Thanks in advance
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it has to be XX.XX
^\d{2}\.\d{2}$

Eric
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't forget to re-escape backslashes if you put the RE in the regexp object directly.



Or if you want nn.nn exactly, like Eric said, then do:

[ October 19, 2006: Message edited by: Bauke Scholtz ]
 
Alessandro Ilardo
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your help. I partially solved the problem. The field is actually destinated for quantity values starting from 0.00, so should allow numbers such as:
1
2.1
0.1
216.09
12765.00
etc.

Your code actually works fine but accept only values like 20.00

(I know, my mistake. I didn't express myself correctly).

[ October 19, 2006: Message edited by: Alessandro Ilardo ]
[ October 19, 2006: Message edited by: Alessandro Ilardo ]
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try:

^\d+(\.\d+)?$

Eric
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only thing is why reinvent the wheel when you have: http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Functions:isNaN

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic