Validate Field based on String length

Avatar

Avatar
Validate 1
Level 1
deboraha5380687
Level 1

Likes

2 likes

Total Posts

22 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
Applaud 5
View profile

Avatar
Validate 1
Level 1
deboraha5380687
Level 1

Likes

2 likes

Total Posts

22 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
Applaud 5
View profile
deboraha5380687
Level 1

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)

Avatar

Avatar
Springboard
MVP
Magus069
MVP

Likes

143 likes

Total Posts

1,078 posts

Correct reply

155 solutions
Top badges earned
Springboard
Validate 1
Ignite 3
Ignite 1
Establish
View profile

Avatar
Springboard
MVP
Magus069
MVP

Likes

143 likes

Total Posts

1,078 posts

Correct reply

155 solutions
Top badges earned
Springboard
Validate 1
Ignite 3
Ignite 1
Establish
View profile
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)

Avatar

Avatar
Coach
MVP
radzmar
MVP

Likes

397 likes

Total Posts

2,687 posts

Correct reply

492 solutions
Top badges earned
Coach
Ignite 3
Ignite 1
Validate 1
Give Back 50
View profile

Avatar
Coach
MVP
radzmar
MVP

Likes

397 likes

Total Posts

2,687 posts

Correct reply

492 solutions
Top badges earned
Coach
Ignite 3
Ignite 1
Validate 1
Give Back 50
View profile
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.");
}