aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes float regexp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "float regexp" Watch "float regexp" New topic
Author

float regexp

Alessandro Ilardo
Ranch Hand

Joined: Dec 23, 2005
Posts: 218
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


trying to decode a woman mind....
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
If it has to be XX.XX
^\d{2}\.\d{2}$

Eric
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
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

Joined: Dec 23, 2005
Posts: 218
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
try:

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

Eric
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Only thing is why reinvent the wheel when you have: http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Functions:isNaN

Eric
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: float regexp