• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Simple regular expression!

 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to use regular expression to test if a price (decimal) has the correct format:

Now I�m allowed to type in a positive integer with 2 decimals, i.e. 15.50.

Script:
document.form1.productPrice.value.match(/^\d+(\.\d{2})?$/)

I also want to be able to type in a positive integer with 1 decimal only!

Have can I do that?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
{1,2}
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic