J
J
jack3d2015-05-25 10:15:24
JavaScript
jack3d, 2015-05-25 10:15:24

How can I set a field with input type="text" using javascript to only accept numbers with a range of 00 to 60?

You cannot change the field type to input type="number".

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
twobomb, 2015-05-26
@jack3d

Look, it's very tough of course.
https://jsfiddle.net/twobomb/p7027rv3/

D
Denis Ineshin, 2015-05-25
@IonDen

Only check for JS: jsfiddle.net/IonDen/sbLktg1f

var input = document.getElementById("test");

var check = function () {
    var val = +this.value;
   
    if (typeof val === "number" && val < 0) {
        this.value = 0;
    }
    
    if (typeof val === "number" && val > 60) {
        this.value = 60;
    }
    
    if (isNaN(val)) {
        this.value = "";
    }
};

input.addEventListener("keyup", check, false);

_
_ _, 2015-05-25
@AMar4enko

Make a directive, keep track inside keypress and implement the desired logic.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question