Edit: as per Alex's answer, there is a field in HTML5, so my statement about there not been one is incorrect.
There is no numeric up down field in HTML, so I'm presuming you're using a javascript implementation ( something like this http://www.htmlforums.com/client-side-scripting/t-help-with-numericupdown-control-59399.html ).
Have the onclick event for the up and down buttons trigger a JavaScript function. In this function have it check the value that it is changing to using an if statement, and if it's too large, don't increase it, and vice versa.
You'd want something along the lines of below. I haven't used javascript for a little while so I can't vouch for the correct syntax.
if (document.getElementById("input1").value < 5)
{
document.getElementById("input1").value++
}
As for key presses, check out http://www.w3schools.com/jsref/event_onkeypress.asp . Use this to trigger the same functions that the up and down buttons on the web page trigger.