Validate Field based on String length

deboraha5380687

07-01-2020

Hi all,

 

I want to validate a text field (string, named "Kontierungselement") based on the length. So allowed are 10, 8 or 7 char. I limited the field to 10 char. But for every other input there should be an error message. I put the error message in the validate script message of the object and tried it with this code inside the validate event. 

But my problem is that the length (currentLength) is not working - I all the time see 0 instead of the correct value, any ideas?

 

FormServiceRequestConfirmation.mstPageSet1.mstPage1.frmTitle.Kontierungselement::validate - (JavaScript, client)
console.show();
var currentLength = xfa.event.newText.length;
console.println(currentLength);
var kontierungselement = FormServiceRequestConfirmation.mstPageSet1.mstPage1.frmTitle.Kontierungselement;
console.println(kontierungselement.length);

if(currentLength != 10 && currentLength != 8 && currentLength != 7){
result = false;
}

 

Thanks a lot! 

Deborah

Accepted Solutions (1)

Accepted Solutions (1)

Magus069

MVP

07-01-2020

Hi there,

 

if you are using xfa.event.newText, it should be within the "enter" event. 

Any other event will need to use this.rawValue instead.

 

I hope this will help

Answers (1)

Answers (1)

radzmar

MVP

07-01-2020

The rawValue is only updated when you exit a field.

You can use a script with regular expression in the exit event to test against the rawValue.

 

if (this.rawValue.match(/^(\D{7,8}|\D{10})$/) === null) {

    xfa.host.messageBox("Invalid value entered.");
}