Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Set focus on phone number field when validations fails

Geckoz100
Level 5
Level 5

Hello,

I have a text field set up as a phone number field, with the following in the change event to accept numbers only:


if(xfa.event.newText.match(/[^0-9]/)){


xfa.event.change = "";


}


In the Pattern validation, I have this mask on all tabs (Display, Edit, Validation and Data):

text{'('999')' 999-9999}

I want the user to be able to just enter numbers and have the parentheses and dash added automatically ["(123)-456-7890"].


How do I get the focus to stay on this field when it fails validation? (e.g., insufficient or too many digits).  I have looked into validationState but couldn't figure out how to use it (I'm a noob javascripter).

Thanks for any help.

1 Accepted Solution
jasotastic81
Correct answer by
Level 7
Level 7

in the exit event of your field:


if (this.rawValue.length !=9) xfa.host.setFocus(this);


View solution in original post

3 Replies
jasotastic81
Correct answer by
Level 7
Level 7

in the exit event of your field:


if (this.rawValue.length !=9) xfa.host.setFocus(this);


View solution in original post

Geckoz100
Level 5
Level 5

That worked, thanks!  The only change I made was to insert "10" instead of "9" for the phone digits.


if (this.rawValue.length != 10) xfa.host.setFocus(this);


jasotastic81
Level 7
Level 7

Yeah, I'll learn how to count one day...