Skip to main content
Participant
Jan 17, 2017 3:23 PM UTC
Answered

How to Allow Only Certain Characters to be typed in a Field

Hello everyone,

I have only recently started working with Adobe Acrobat Pro, so my apologizes if this a rather simple question.

I am trying to create fields for telephone numbers. I am aware that in the Format Category there is an option for phone numbers.  However, only works for 10 character phone numbers.  For people living in other countries, this may be a problem.

What I would like to know is that is there a way to set a field so that only the user can only input certain characters.  For this particular field I would like them to be only able to input numbers "0-9", dashes " - ", periods " . " , or Parenthesis " ( ) " .  They do not need to be in a particular order.

I appreciate the help!

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Jan 17, 2017 4:51 PM UTC

This kind of validation is best done using something called a Regular Expression. You can read up about it how to use them in JavaScript, but here's the code that achieves what you described. It should be entered as the field's custom Keystroke script:

if (event.change) {

     event.rc = /^[0-9,\.\(\)]+$/.test(event.change);

}

9 replies

Inspiring
Jan 17, 2017 5:42 PM UTC

As noted this can be done with the Regular Expression object. For a specific country we would need to know the format of the phone numbers for that country.

Acrobat is supplied with the U.S, and Canadian phone number masks. These masks include the keystroke, validation, and formatting masks.

You might be able find the formatting masks on the Internet but the keystroke and validation masks are unique to Acrobat forms.

Translate
Known Participant
Dec 13, 2024 1:02 PM UTC


Agreed however, my stakeholders wants it to be generic as well as 19 characters to accomodate any country. One thing this code doesn't have is the restriction to keep it only to numbers, special characters & spaces.  Is this possible in Adobe Acrobat? 

 

Much thanks for your help!

Translate
try67
Community Expert
Community Expert
Dec 13, 2024 1:37 PM UTC

Yes, you can do that using the code I provided above. You can add any additional characters you want to allow within the square brackets of the RegExp.

Translate
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Jan 17, 2017 4:51 PM UTC

This kind of validation is best done using something called a Regular Expression. You can read up about it how to use them in JavaScript, but here's the code that achieves what you described. It should be entered as the field's custom Keystroke script:

if (event.change) {

     event.rc = /^[0-9,\.\(\)]+$/.test(event.change);

}

Translate
Participant
Jul 20, 2022 7:18 AM UTC

This is great. Is there a way so that the numeric keyboard is still displayed by default using ipad?

 

Cheers.

Translate
try67
Community Expert
Community Expert
Jul 20, 2022 8:04 AM UTC

No.

Translate