Hello,
I have a field which the user enters a number. The field is 9 digits long, and the number that the user enters needs to start with the number 1. Is it possible to format the field to start with a 1?
Thank you,
Nik
Solved! Go to Solution.
Views
Replies
Total Likes
My preference is use a Text Field object and script to do validation. This may not be for everyone. I defined a Text Field called 'tf' with a maximum character length of 9 and added the script below to the exit event.
// form1.page1.tf::exit - (JavaScript, client)
if (!(this.isNull)) {
var tf = this.rawValue;
var regExp = /^\d{9}$/;
if (regExp.test(tf)) {
if (tf.substr(0,1) != "1") {
xfa.host.messageBox("The field must be start with a 1.","Validation",1);
}
}
else {
xfa.host.messageBox("The field must be 9 digits starting with a 1.","Validation",1);
}
}
Views
Replies
Total Likes
My preference is use a Text Field object and script to do validation. This may not be for everyone. I defined a Text Field called 'tf' with a maximum character length of 9 and added the script below to the exit event.
// form1.page1.tf::exit - (JavaScript, client)
if (!(this.isNull)) {
var tf = this.rawValue;
var regExp = /^\d{9}$/;
if (regExp.test(tf)) {
if (tf.substr(0,1) != "1") {
xfa.host.messageBox("The field must be start with a 1.","Validation",1);
}
}
else {
xfa.host.messageBox("The field must be 9 digits starting with a 1.","Validation",1);
}
}
Views
Replies
Total Likes
Thank you for your help. I do have one more question. If i enter in a number that starts with somethign other than 1 it gives me the error message
but the number still shows up in the field. If i leave it there, it still lets me submit the form, even though the format was incorrect. Since the field is not mandatory can i still make it mandatory that the correct number is entered?
Views
Replies
Total Likes
There are a variety of techniques for getting this done. It depends on how you want to present error messages. One easy technique is to define your submit button, make it "hidden", and add a second "regular" button which executes validation script and calls the "click" event on the hidden submit button.
// form1.page1.callSubmitBtn::click - (JavaScript, client)
if (form1.page1.tf.isNull) {
xfa.host.messageBox("Text field is a mandatory field.");
}
else {
form1.page1.submitBtn.executeEvent("click");
}
Steve
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies