function prettify (num) {
var n = num.toString();
var separator = " ";
return n.replace(/(\d{1,3}(?=(?:\d\d\d)+(?!\d)))/g, "$1" + separator);
}
var $test = $(".test");
var val = $test.prop("value");
$test.prop("value", prettify(val));
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);