Expand my Community achievements bar.

How to limit to enter a IP address in TextField?

Avatar

Level 2

Hello everyone,

I have a PDF form which users need to enter a IP address. In order to get a correct IP address, I need to limit a TextField's pattern.

What my boss want me to realize is like the picture below:

ipAddressSet.jpg

It means when users fill 3 numbers of IP address, it will jump to next place and display a point "." automatically.

But I found it can't change the rawvalue of the TextField when it is in a typing status(in Change event).

Do you think if I can realize this requirement? How can I do ?

Thanks a lot!

Elly

1 Reply

Avatar

Level 10

Hi,

you can use a regular expression to verify the entered text.

This script in the fields exit event, will check the entered text against a regular expression.


if (! this.rawValue.match(/\b(?:(?:2(?:[0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9])\.){3}(?:(?:2([0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9]))\b/ig)) {


     xfa.host.messageBox("invalid IP-Address");


}


Here`s a source for regular expression you can try.

RegExr: Learn, Build, & Test RegEx