Skip to main content
Participant
January 17, 2017
Answered

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

  • January 17, 2017
  • 2 replies
  • 4712 views

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 has been closed for replies.
Correct answer try67

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);

}

2 replies

Inspiring
January 17, 2017

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.

Known Participant
December 13, 2024


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!

try67
Community Expert
Community Expert
December 13, 2024

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.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
January 17, 2017

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);

}

Participant
July 20, 2022

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

 

Cheers.

try67
Community Expert
Community Expert
July 20, 2022

No.