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
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;
}
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'.
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.
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?
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;
}
Copy link to clipboard
Copied
Thank you, but unfortunately this has the same output...
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.
Copy link to clipboard
Copied
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'.
Copy link to clipboard
Copied
Thank you very much! You helped me a lot to understand the scripting in PDF forms! It works now!