workpage,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<script>
document.addEventListener( "DOMContentLoaded" , function() {
const on = (parent, event, selector, handler) => parent.addEventListener(event, ({target}) => {
if(target = target.closest(selector)) handler(target);
});
const limit = (min, max) => el => {
let txt = el.value, reg = /\D/g;
if(reg.test(txt)){
reg.lastIndex = 0;
txt = txt.replace(reg, "");
};
let num = Math.max(min, Math.min(+txt, max));
el.value = txt && num != txt ? num : txt;
};
on(document, "input", ".num", limit(1, 255));
});
</script>
</head>
<body>
<input type="text" maxlength="3" value="" class="num" /></body>
</html>