I find numeric fields to be cumbersome when it comes to form validation so I use text fields and regular expressions.
Additionally, you can set the length (max characters) to control the upper limit thus avoiding an edit. So in your case, set the max characters to 4. If the field is not mandatory, check to see if it is not null. If it is entered, the regular expression checks that the value has a length of 4 and contains digits only.
if (!(form1.page1.nf1.isNull)) {
var regExp = /^\d{4}$/;
if (!(regExp.test(form1.page1.nf1.rawValue))) {
xfa.host.messageBox("Please enter four digits.");
}
}
Steve