Welcome to WebmasterWorld Guest from 54.242.193.41

Forum Moderators: open

Floats and digits

     
1:38 pm on May 16, 2019 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:Oct 25, 2006
posts: 1103
votes: 1


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"
5:42 pm on May 16, 2019 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:15706
votes: 813


Ordinarily this is what the toFixed(2) statement is for. Is there a reason you canít use it?
10:03 am on May 22, 2019 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:Oct 25, 2006
posts: 1103
votes: 1


I have tested the following HTML:
<input id="xxx" type="number" name="xxx" data-parsley-pattern="[0-9]*(\.?[0-9]2$)" data-parsley-type="number" required data-parsley-trigger="change"/>

It will be shown on the right hand side some listbox 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