Expand my Community achievements bar.

SOLVED

Mandatory number of characters

Avatar

Level 2

Hello,

I have a field that is required. I have it set to required and I have the characters set to 6. I can still enter 1 number and there is no error. I need this field to validate that it has 6 characters. Can anyone help me with a script?

1 Accepted Solution

Avatar

Correct answer by
Level 4

you may also want to check for > 6 too, if you are saying they can only have 6 characters in the field.  Validation pattern would ahve been just as good, but it's personal preference.

View solution in original post

7 Replies

Avatar

Level 10

Hi,

Having the following javascript in the exit event will warning the user and set the focus back to the field:

if (this.rawValue.length < 6)

{

     app.alert("This field must have at least 6 digits");

     xfa.host.setFocus(this);

}

Good luck,
Niall

Avatar

Level 4

You could also apply a validation pattern to the field with something like text{999999}

Avatar

Level 2

Hello and thank you so much for your help. I was able to use:

if

(Speedtype.length < 6)then

Speedtype

=""

xfa.host.messageBox("This field must have at least 6 digits")

else

Speedtype

=Speedtype

endif

This worked for me well, I wouldn't have been able to find it without your help. Thanks so much

Avatar

Correct answer by
Level 4

you may also want to check for > 6 too, if you are saying they can only have 6 characters in the field.  Validation pattern would ahve been just as good, but it's personal preference.

Avatar

Level 2

Ok so I got it to work using the validations. Much Much easier. no scripting needed but it is good to know both ways. Thanks both of you for all your help. i'm sure we will cross paths again.

Avatar

Level 4

you can ignore my e-mailed solution then   Glad to hear you got the validation to work!