-2

I have a field called price, now how to validate this field by java script? It will take only integer value and dot. It may take decimal point or not. e.g 200,200.00 both are valid. How shall I do that?

1
  • 3
    "only take characters" ... what would the other possibilities be?
    – Pointy
    May 14, 2012 at 11:49

1 Answer 1

0

There are many ways to achieve this.

Without the use of any 3rd party libraries i would recommend using regular expressions.

A possible pattern used to validate price would be

\d[\d\,\.]+

here is a tutorial on using regular expressions to validate fields in java-script

Tutorial

Hope this helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.