Bootstrap number validation

It’s not Twitter bootstrap specific, it is a normal HTML5 component and you can specify the range with the min and max attributes (in your case only the first attribute). For example:

<div>                       
    <input type="number" id="replyNumber" min="0" data-bind="value:replyNumber" />
</div>

I’m not sure if only integers are allowed by default in the control or not, but else you can specify the step attribute:

<div>                       
    <input type="number" id="replyNumber" min="0" step="1" data-bind="value:replyNumber" />
</div>

Now only numbers higher (and equal to) zero can be used and there is a step of 1, which means the values are 0, 1, 2, 3, 4, … .

BE AWARE: Not all browsers support the HTML5 features, so it’s recommended to have some kind of JavaScript fallback (and in your back-end too) if you really want to use the constraints.

For a list of browsers that support it, you can look at caniuse.com.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)