Use the maxLength attribute of the input. So, on page load, do the following:
$("#XXXX").attr('maxlength','5');
Edit based on comments : In order to apply rule to all numeric boxes, the following should work:
$("input[data-role='numerictextbox']").attr('maxlength','5');