• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

float regexp

 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it has to be XX.XX
^\d{2}\.\d{2}$

Eric
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try:

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

Eric
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
permaculture is largely about replacing oil with people. And one tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic