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

Format eines Textfeldes für Telefonnummern

Community Beginner ,
Nov 24, 2023 Nov 24, 2023

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
1.6K
Translate
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
2 ACCEPTED SOLUTIONS
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;
}

View solution in original post

Translate
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

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'.

View solution in original post

Translate
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

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.

Translate
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

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?

Translate
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

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

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

Translate
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

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.

Translate
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

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

Translate
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

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'.

Translate
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
LATEST

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

Translate
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