Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
This is great. Is there a way so that the numeric keyboard is still displayed by default using ipad?
Cheers.
Copy link to clipboard
Copied
No.
Copy link to clipboard
Copied
This works almost perfect for me... however to make it perfect, is there a way to tell this js in adobe pro to use spaces whereever you see fit in addition to what's already implemented?
Copy link to clipboard
Copied
Use this:
if (event.change) {
event.rc = /^[0-9,\.\(\) ]+$/.test(event.change);
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thanks again... I'll give it a shot