Parsley validation and floats or digits

Validation:https://parsleyjs.org/

I try to implement floats and also digits. When I have numbers for the price in USA format it will not be the correct code. How to manage floats or digits. An example:

The price can be 10 USD, 10.55 not 10.5 USD. As I understand it will work required just floats using type=“text” and data-parsley-type=“number”, but how to solve max. two decimals?

Is this working and the correct?
data-parsley-pattern=“[0-9]*(.?[0-9]{2}$)” using type=“text” and data-parsley-type=“number”

I have tested the following HTML:

It will be shown on the right-hand side some list box as it is an error in HTML, but validation will not work. It seems an error in validation. Maybe you have the correct HTML to test floats.
Testing:

  1. It should pass 10.99, 10 as true
  2. It should post an error message (false) when filled in
    10,20
    10,7

Hi @toplisek, I’m not familiar with parsley but generally the pattern should go like ^\d+(\.\d{2})?$ (that is, any non-zero number of digits, optionally followed by a dot and exactly 2 digits).

I is great validation script but missed any demo version to see working condition.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.