Hi All,
I have a form I have just completed, and it is one of those complex one. There is a field that is numeric, and should not accept less than 4 digits. I wrote the following code, but it doesn't seem to work, and I do not know why.
if
(SSN_SMg.rawValue > "" && SSN_SMg.length < 4){
xfa.host.messageBox
="none";
xfa.host.setFocus("SSN_SMg");
}
Please, can someone tell me what I am doing wrong.
Thanks
LP
Solved! Go to Solution.
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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
Views
Replies
Total Likes
Thanks, Steve, that approach works.
Views
Replies
Total Likes