• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Multiple masks for phone numbers

Community Beginner ,
Jun 04, 2021 Jun 04, 2021

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.

TOPICS
Create PDFs , Edit and convert PDFs , How to , JavaScript , PDF forms

Views

2.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 07, 2021 Jun 07, 2021

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

...

Votes

Translate

Translate
Community Expert ,
Jun 04, 2021 Jun 04, 2021

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

?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 04, 2021 Jun 04, 2021

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 04, 2021 Jun 04, 2021

Copy link to clipboard

Copied

That's what I was referring to...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 04, 2021 Jun 04, 2021

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 06, 2021 Jun 06, 2021

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 06, 2021 Jun 06, 2021

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 06, 2021 Jun 06, 2021

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 06, 2021 Jun 06, 2021

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 07, 2021 Jun 07, 2021

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.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 07, 2021 Jun 07, 2021

Copy link to clipboard

Copied

This works perfect! Thank you!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 07, 2021 Jun 07, 2021

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 07, 2021 Jun 07, 2021

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 09, 2021 Jun 09, 2021

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines