Expand my Community achievements bar.

SOLVED

Validate event

Avatar

Level 2

While I am not new to LiveCycle, I AM new to the Validate event, and Validation Pattern and Script Messaging that go along with it. I am having trouble understanding how they work together; it simply doesn't make a lot of sense to me and I cannot seem to find very good information online. I am stuck and need some help.

I have a Numeric Field (PAN) that requires a 16-digit entry. I would like to test to ensure that (a.) only numbers are entered, and (b.) that all 16 digits are entered (no more, no less). If not, I want to throw a error message and set the focus back on the field. I have tried combs, and setting the maximum number of characters, but this does not prevent a fewer number of characters. Other things I've tried do not do exactly what I want either.

Perhaps I'm overthinking this, but here's where I've ended up in trying to solve this problem. What is the best way to accomplish that I'm trying to do?

1. Regular expression in the validate event:

       Then on the Value tab of the Object panel, I have the following Validation Script Message (I don't have a Validation Pattern Message defined: should I?):

The example above doesn't work as expected: it returns a Validation error message even when 16 numerical digits are entered. I've tried experimenting with other Display, Edit, and Validation patterns, like ("num{9999999999999999}"), or ("num{zzzzzzzzzzzz9}"), but it still does strange things. For example, letters are still allowed to be input, or the result is reformatting with commas after failing the validation.

Any help you can offer would be appreciated.

--Bruce

1 Accepted Solution

Avatar

Correct answer by
Level 6

Place a text field and use the below script on the "exit" event of the "textfield".

Also u can Limit the length to 16 on "Object -> Field" properties of the text field.


if(this.rawValue != "" && this.rawValue != null){
var txtResult = validateNumber(this.rawValue);
if(!txtResult){
  xfa.host.messageBox("Error Message Text here: Should be 16 digits.");
  xfa.host.setFocus(this);
}
}

//Function validates it is a number and has 16 digits.
function validateNumber(str){
var filter=/^\d{16}$/i
if (filter.test(str))
  testresults=true
else{
  testresults=false
}
return (testresults)
}

Hope this helps.

-Raghu.

View solution in original post

2 Replies

Avatar

Correct answer by
Level 6

Place a text field and use the below script on the "exit" event of the "textfield".

Also u can Limit the length to 16 on "Object -> Field" properties of the text field.


if(this.rawValue != "" && this.rawValue != null){
var txtResult = validateNumber(this.rawValue);
if(!txtResult){
  xfa.host.messageBox("Error Message Text here: Should be 16 digits.");
  xfa.host.setFocus(this);
}
}

//Function validates it is a number and has 16 digits.
function validateNumber(str){
var filter=/^\d{16}$/i
if (filter.test(str))
  testresults=true
else{
  testresults=false
}
return (testresults)
}

Hope this helps.

-Raghu.

Avatar

Level 2

That worked! Thank you so much, Raghu!