Copy link to clipboard
Copied
Hello community!
I'm trying to set up a mask for my phone numbers field in Acrobat Pro DC.
The problem is I only want one field for the phone numbers to enter, but the length of a mobile number and the ones of the company are different AND a mobile number needs another mask then the ones for the company. And last but not least, the lenght of the company phone number has to be variable.
So.. the mobilenumbers can be 10 or 11 signs long and the companys phone numbers can be 8 to like 13 signs long. And if the lenght changes, the mask must change too..
I tried to write my own JavaScript, but I'm a total beginner and I'm not good enough to write the right one. 😄
the Masks should look something like this:
for the companys: (they have to work international)
(+XX) XXXX-XXX
(+XX) XXXX-XXXX
(+XX) XXXX-XXX XX
(+XX) XXXX-XXX XXX
(+XX) XXXX-XXX XXX-X
(+XX) XXXX-XXX XXX - XX
for mobile: (they have to work international)
(+XX) XXX-XX XXX XX
(+XX) XXX XXX XXX
I hope you understand my problem.
If mobile numbers starts with 491 you can try something like this as custom format script (adapt it as you wish):
var v = event.value;
var str = v.substr(0, 3);
if(v.length == 9)
v = util.printx("(+99) 9999-999", v);
else if(v.length == 10)
v = util.printx("(+99) 9999-9999", v);
else if(v.length == 11){
if(str == "491")
v = util.printx("(+99) 999 999 999", v);
else
v = util.printx("(+99) 9999-999 99", v);}
else if(v.length == 12){
if(str == "491")
v = util.printx("(+99) 999-99 999 99", v);
else
v = util.print
Copy link to clipboard
Copied
This is not possible. How would the script know whether to format a 12-digit string using this format:
(+XX) XXXX-XXX XXX
Or this one:
(+XX) XXX-XX XXX XX
?
Copy link to clipboard
Copied
Well then, Could it be possible to script that in JavaScript?
Copy link to clipboard
Copied
That's what I was referring to...
Copy link to clipboard
Copied
Oh I'm sorry, I missunderstood your response.
Well, back to your previous question. This format mostly starts with a one in germany:
(+XX) 1XX-XX XXX XX
It could be an option to say, that if it starts with (+49) 1 .... (a typical german mobilephone beginning) it should use the format:
(+XX) XXX-XX XXX XX
and if it doesn't it could use the format:
(+XX) XXX XX XXX XX.
Copy link to clipboard
Copied
Hi,
I only discovered this post yesterday, so I hope it's not too late!
I wrote a regular expression allowing the 8 masks you need for your phone numbers:
/^(\(\+\d{2}\)\ \d{3})((\d[-]\d{3})((\d)|([ ]\d{2})((\d)(([-]\d)|(( - )\d{2}))?)?)?|([-]\d{2}[ ]\d{3}[ ]\d{2})|([ ]\d{3}[ ]\d{3}))$/
In the supplied example you will find the scripts for checking the masks in typing management or with an alert message.
@+
Copy link to clipboard
Copied
This works for validation, but I think the point is to automatically apply the mask as a custom Format, ie. the user only enters the digits and the mask formats the number to have the other characters. And as I said, that's not possible if you have multiple formats for the same number of digits.
Copy link to clipboard
Copied
I understood what you meant it's correct these are not really masks because you have to type hypens and spaces, but you can't type any other formats than those allowed...
and this not only for validation but for typing management too.
Copy link to clipboard
Copied
Thanks to both of you!
I think I need two boxes in my document. One for the mobile numbers and one for the others. Then it should be possible to script that, right?
Copy link to clipboard
Copied
If mobile numbers starts with 491 you can try something like this as custom format script (adapt it as you wish):
var v = event.value;
var str = v.substr(0, 3);
if(v.length == 9)
v = util.printx("(+99) 9999-999", v);
else if(v.length == 10)
v = util.printx("(+99) 9999-9999", v);
else if(v.length == 11){
if(str == "491")
v = util.printx("(+99) 999 999 999", v);
else
v = util.printx("(+99) 9999-999 99", v);}
else if(v.length == 12){
if(str == "491")
v = util.printx("(+99) 999-99 999 99", v);
else
v = util.printx("(+99) 9999-999 999", v);}
else if(v.length == 13)
v = util.printx("(+99) 9999-999 999-9", v);
else if(v.length == 14)
v = util.printx("(+99) 9999-999 999 - 99", v);
else{
app.alert("Please enter correct number format.", 3);
v = "";}
event.value = v;
For another solution, if your mobile or phone numbers starts same you can also add checkbox for mobile phones and check it if it's mobile phone and then use script to input correct format depending on checkbox state.
Copy link to clipboard
Copied
This works perfect! Thank you!
Copy link to clipboard
Copied
Thom Parker gave me this script on this forum a few years ago, it checks the International phone format.
It allows digits, period, space and plus sign, use it as Custom Keystroke Script:
var regxp=/^[0-9.\+\s]$/;
if (event.willCommit==false) {
if (event.change.length>0 && regxp.test(event.change)==false) {
app.beep();
event.rc=false
}
}
Copy link to clipboard
Copied
Hi JR
In this expression, both parenthesis signs and a hyphen are missing and it only checks the keys you're typing, not the format of the phone number. And here you don't need the period.
var regxp=/^[0-9\+\s\(\)\-]$/; will check all characters.
You can only check the correct format while validating.
But it seems it's enough there!
@+
Copy link to clipboard
Copied
Merci pour la regex, par-contre il est normal que ce Custom Keystroke Script ne vérifie que la saisie en cours car c'était voulu ainsi.