Donald T
Donald T

Reputation: 10667

HTML5 input: Whole number step with decimal min

I have an HTML5 number input with a min of 0.01 and a step of any. But for the user, the first "step" is 0.01, and subsequent steps include ".01".

I want to enforce a minimum value of 0.01 while allowing the user to step in whole numbers (i.e., 1, 2, 3, etc.).

How is this possible?

Upvotes: 3

Views: 700

Answers (1)

Chuck Le Butt
Chuck Le Butt

Reputation: 48798

I think you're going to have to use JavaScript. With jQuery it would be:

$('input').on('change', function() {
  var $this = $(this);
  if ($this.val() < 0.01) {
    $this.val('0.01');
  }
});

JSFiddle

Upvotes: 2

Related Questions