Copy link to clipboard
Copied
Hi guys,
I am also unsure if I should be inserting the code on Format or Validate.
If there's any tutorial on the JavaScript language for Adobe Acrobat, kindly leave links down below because I would like to learn more on this.
Thanks in advance for anyone that will be kind to help!
Copy link to clipboard
Copied
Adobe only supplies a predefined format for North American phone numbers entered as a 10 digit number, "[(]999[)][--. ]999[-. ]9999". This is all done using the RegExp object. The tutorials start with the W3 schools and other web sites The RegExp is common to many languages besides JavaScript. If you write your own validation script you may also need to write you own custom keystroke and custom format scripts.
Copy link to clipboard
Copied
What if I want to just have the textfield as a Custom format since I'm not from North American?
I was using this code previously that I found which worked well since I only needed to have the textfield in numbers:
// Document-level function
function triDigKS() {
// Get all that is currently in the field
var val = AFMergeChange(event);
// Reject entry if anything but digits
event.rc = AFExactMatch(/\d{0,10}/, val);
}
// Custom Keystroke script
triDigKS();
---------
However, I was required to allow additional "-" and "+" characters on top of numerics, but I have no idea how.
Copy link to clipboard
Copied
Why not just add the RegExp for the "+" character?
// Document-level function
function triDigKS() {
// Get all that is currently in the field
var val = AFMergeChange(event);
// Reject entry if anything but "+" with digits or a null string;
event.rc = AFExactMatch(/^[+]\d{0,10}$/, val));
return;
}
I am not sure where you want the "-" separators to appear.
This code does not allow for the manual removing of the plus sign and number or optionally not entering the "+" as part of the number. That is easily fixed by adding additional RegExp strings to the array for the AFExactMatch function.
When one writes code one needs to have a clear and full statement of the requirements.
Copy link to clipboard
Copied
Thanks for your kind reply.
However, it is still not what I'm looking for.
I tried a few ways to edit the code to what I want, but I don't quite understand how your code works
"event.rc = AFExactMatch(/^[+]\d{0,10}$/, val)".
"-" is supposed to allow user to indicate a NIL input.
"+" is supposed to allow user to include an overseas mobile number.
Hence, user is supposed to be able to remove any character if possible.
Copy link to clipboard
Copied
The code uses the RegExp, Regular Expression, object to indicate what is required or optional by position in the string. This is common object used in many computer languages and applications. There are many tutorials and tools on the web and books that cover this tool and how to use it. The use of this tool requires that one clearly can completely describe all the possible ways the string could be displayed. You may need to write several pieces of code for the keystroke, format, and validation of the data.
It sounds like you will need both the North American phone numbers and international phone number scripts.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now