Reputation: 1168
How can I validate an input to have an exact amount of decimals? For instance, if I want to validate a number to have 2 decimals then I want to validate as follow:
Upvotes: 3
Views: 8865
Reputation: 91
From java script answer for decimal validation
data-parsley-pattern="^\d+(.\d{1,2})?$"
also, please check if input type="text"
Upvotes: 0
Reputation: 11
You could use the data-parsley-pattern attribute, and use a regular expression to match numbers to 2 decimal places or zero.
^[0-9]{1,}\.?[0-9]{0,2}$
for example:
Upvotes: 1
Reputation: 10618
You could use the data-parsley-pattern
attribute, and use a regular expression to match number to 2 decimal places:
data-parsley-pattern="^[0-9]*\.[0-9]{2}$"
Also, remember to add a required
attribute to your tag.
Upvotes: 13