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

Format eines Textfeldes für Telefonnummern

Community Beginner ,
Nov 24, 2023 Nov 24, 2023

Copy link to clipboard

Copied

Hallo!

Ich habe gerade mit Adobe Pro gestartet und stehe nun vor folgendem Problem:

In mein Formular sollen Telefonnr. eingetragen werden, welche eine unterschiedliche Länge aufweisen können.

Lege ich nun mit dem Format Spezial eine Beliebige Maske fest, stehe ich vor dem Problem, dass ich es nicht schaffe, die Länge Variabel zu machen (wie bei regulären Ausdrücken):

+99-999-9...

Nehme ich anstelle von Spezial, Benutzerdefiniert, weiß ich nicht genau, wie ich den den JavaScript Code formulieren muss.

Kann mir bitte jemand dabei helfen?

Vielen Dank!

Conny

TOPICS
How to , JavaScript , PDF forms

Views

332

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 2 Correct answers

Community Expert , Nov 24, 2023 Nov 24, 2023

Try this:

var str = "+";
if (event.value) {
    for (var i = 0; i < event.value.length; i++) {
        str += event.value[i];
        if (i === 2 || i === 5) {
            str += "-";
        }
    }
    event.value = str;
}

Votes

Translate

Translate
Community Expert , Nov 25, 2023 Nov 25, 2023

Under 'Calculate' tab you have selected 'Value is the' which is a calculation that set field to 0, instead select first option 'Value is not calculated'.

Votes

Translate

Translate
Community Expert ,
Nov 24, 2023 Nov 24, 2023

Copy link to clipboard

Copied

You can use something like this as 'Custom format script':

var phone8 = util.printx("+99-999-999", event.value);
var phone9 = util.printx("+99-999-9999", event.value);

if(event.value){
 if(event.value.length == 8)
  event.value = phone8;
 else if(event.value.length == 9)
  event.value = phone9;}

You can easily add more number formats as needed.

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 ,
Nov 24, 2023 Nov 24, 2023

Copy link to clipboard

Copied

Thank you very much for your help! I have used your code to adapt it to my form. Unfortunately, I don't know how many characters to enter. My code now looks like this:

var str  = "+";
var tel;

if (event.value){
    for(var i=0; i<event.value.length; i++){
        str = str + "9";
        if (i==2 || i==5){
            str = str + "-";
        }
    }
}
tel = util.printx(num, event.value);
event.value = tel;

When I test the form now, I always get +0, regardless of the input.

Can you tell me what the reason is?

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 ,
Nov 24, 2023 Nov 24, 2023

Copy link to clipboard

Copied

Try this:

var str = "+";
if (event.value) {
    for (var i = 0; i < event.value.length; i++) {
        str += event.value[i];
        if (i === 2 || i === 5) {
            str += "-";
        }
    }
    event.value = str;
}

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 ,
Nov 24, 2023 Nov 24, 2023

Copy link to clipboard

Copied

Thank you, but unfortunately this has the same output...

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 ,
Nov 24, 2023 Nov 24, 2023

Copy link to clipboard

Copied

With the script I posted above, if you enter:

123456789 = +123-456-789

12345678 = +123-456-78

1234567890 = +123-456-7890

Script should be placed as 'Custom Format Script' under 'Format' tab → 'Custom' → 'Custom Format Script', make sure there are no other script that could affect value of the field.

If you have trouble to make it work, share your file with us.

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 ,
Nov 25, 2023 Nov 25, 2023

Copy link to clipboard

Copied

I put it on the right place and it is the only script in the File. I've also tried to change it do only two =  in the if, but there was the same result.

Here is my file

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 ,
Nov 25, 2023 Nov 25, 2023

Copy link to clipboard

Copied

Under 'Calculate' tab you have selected 'Value is the' which is a calculation that set field to 0, instead select first option 'Value is not calculated'.

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 ,
Nov 27, 2023 Nov 27, 2023

Copy link to clipboard

Copied

LATEST

Thank you very much! You helped me a lot to understand the scripting in PDF forms! It works now!

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