Skip to main content
Participating Frequently
November 24, 2023
Answered

Format eines Textfeldes für Telefonnummern

  • November 24, 2023
  • 1 reply
  • 2311 views

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

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

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


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

1 reply

Nesa Nurani
Community Expert
Community Expert
November 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.

Participating Frequently
November 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?

Nesa Nurani
Community Expert
Community Expert
November 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;
}