Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Open
Description
Your environment
- Version of
jquery-validate: 1.19.5 - Browser name and version: Firefox 116.0.2
Current behavior
Wheninput[type="number"] has an attributestep with value of magnitude smaller than approx. 1e-7, thestep rule has its value assigned in an exponential form, causing regular expression not to being matched.
Expected behavior
Proper input validation, taking actual number of decimal places into account.
Live demo
https://jsfiddle.net/ydj8o4nu/
Hotfix proposal
After reconsideration, I see it might not cover all possible cases, but alternate solutions liketoLocaleString are even more dodgy.
decimalPlaces = function( num ) { var exponentialMatch = ( "" + num ).match( /(?:e\-(\d+))?$/ ); if ( exponentialMatch && exponentialMatch[1] ) { return parseInt(exponentialMatch[1]); } var match = ( "" + num ).match( /(?:\.(\d+))?$/ ); if ( !match ) { return 0; } // Number of digits right of decimal point. return match[ 1 ] ? match[ 1 ].length : 0; },