Skip to main content
Participating Frequently
June 4, 2021
Answered

Multiple masks for phone numbers

  • June 4, 2021
  • 2 replies
  • 4065 views

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.

This topic has been closed for replies.
Correct answer Nesa Nurani

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?


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.

 

2 replies

JR Boulay
Community Expert
Community Expert
June 7, 2021

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
}
}

Acrobate du PDF, InDesigner et Photoshopographe
bebarth
Community Expert
Community Expert
June 7, 2021

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!
@+

JR Boulay
Community Expert
Community Expert
June 9, 2021

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.

Acrobate du PDF, InDesigner et Photoshopographe
try67
Community Expert
Community Expert
June 4, 2021

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

?

LeMa-SAMAuthor
Participating Frequently
June 4, 2021

Well then, Could it be possible to script that in JavaScript?

try67
Community Expert
Community Expert
June 4, 2021

That's what I was referring to...