I am trying to limit the input for a particular field to 3 digit numeric exactly. I am using a regular expression as follows:

if (!/\d{3}/.test(theForm.code.value)) {
alert("Field should have 3 digits only.");
theForm.code.focus();
return false;
}

I have also tried 3,3 instead of 3 and it seems like either should work but while it forces at least 3 digits it also allows 4 or more and I don't want that. Must be 3 exactly.

Can anyone help me please - regular expressions are not one of my strong points!!!!

Paul