Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

step automatic rule gets broken for very small steps #2469

Open
bderleta opened this issue Aug 17, 2023 · 2 comments
Open

step automatic rule gets broken for very small steps #2469

bderleta opened this issue Aug 17, 2023 · 2 comments

Comments

@bderleta
Copy link

bderleta commented Aug 17, 2023

Your environment

  • Version of jquery-validate: 1.19.5
  • Browser name and version: Firefox 116.0.2

Current behavior

When input[type="number"] has an attribute step with value of magnitude smaller than approx. 1e-7, the step 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 like toLocaleString 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;
  },
@bytestream
Copy link
Member

Please can you provide a jsfiddle / jsbin demonstrating the problem.

@bderleta
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants