Reference text field make number adobe acrobat

A Format script does not change the field's actual value. It just formats it in a specific way after it was entered. When you return to the field the original value re-appears. If you want to change the field's actual value you can use the Validate event, but beware, this change will apply each time you edit it! So if you add a "+" sign to the start of the string, for example, it will continue adding it each time you edit the field, unless you add a condition not to do so if the "+" sign is alre

Community Expert , May 23, 2022 May 23, 2022 bebarth • Community Expert , May 23, 2022 May 23, 2022

Isn't it better to manage the keystroke than to check the value at the end?
It's exaggerated, but if you have 200 digits to type, isn't it better to indicate the error immediately while typing rather than checking the 200 characters.

Here is a custom keystroke script which allows that:

var modeleRegEx=/^[+]?\d*$/; if(!event.willCommit) < var aTester=event.value.split(""); aTester.splice(event.selStart, event.selEnd-event.selStart, event.change); var testeChaine=aTester.join(""); if (!model
10 Replies 10 Community Expert ,

/t5/acrobat-discussions/field-format-for-telephone-number/m-p/12959664#M363725 May 23, 2022 May 23, 2022

Copy link to clipboard

This is not really formatting, then. It sounds like what you want is a Validation script, to only allow numbers, with or without a "+" before them. Is that correct?

Community guidelines

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

/t5/acrobat-discussions/field-format-for-telephone-number/m-p/12959675#M363727 May 23, 2022 May 23, 2022

Copy link to clipboard

Community guidelines

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

Community Expert ,

/t5/acrobat-discussions/field-format-for-telephone-number/m-p/12959686#M363728 May 23, 2022 May 23, 2022

Copy link to clipboard

You can use this code as the field's custom Validation script, then:

if (event.value) < event.rc = /^\+?\d+$/.test(event.value); if (!event.rc) app.alert("Invalid telephone number format."); >
Community guidelines

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

/t5/acrobat-discussions/field-format-for-telephone-number/m-p/12959731#M363734 May 23, 2022 May 23, 2022

Copy link to clipboard

Ok, it works, although I cannot use Polish letters in the message because there are bushes instead of them.

By the way, an additional question in the same subiect. While trying to solve this problem, I wrote the following script myself.

var tekst=this.getField("Wn_Telefon").valueAsString; var dl=this.getField("Wn_Telefon").valueAsString.length; var tekst_wy=""; var znak=""; for (var i = 0; i if(i>0 && znak!="+") < tekst_wy = tekst_wy + znak; >> event.value=tekst_wy;

The principle of operation is simple. Only the first character can be "+". If "+" appears elsewhere it is ignored.
The script works but has one drawback. Namely, if I enter, for example, "++ 12345 + 678 +", then after pressing TAB and moving to another field, what is needed appears, that is "+12345678". But if I go back to editing this field again, I have "++ 12345 + 678 +" again. So something else is remembered and another displayed. Probably my misunderstanding of events and the order in which the scripts are called.
Of course, as an additional keystroke script is:

if (event.change) event.rc = /^[0-9\+]+$/.test(event.change);
Community guidelines

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

Community Expert ,

/t5/acrobat-discussions/field-format-for-telephone-number/m-p/12959881#M363752 May 23, 2022 May 23, 2022

Copy link to clipboard

A Format script does not change the field's actual value. It just formats it in a specific way after it was entered. When you return to the field the original value re-appears. If you want to change the field's actual value you can use the Validate event, but beware, this change will apply each time you edit it! So if you add a "+" sign to the start of the string, for example, it will continue adding it each time you edit the field, unless you add a condition not to do so if the "+" sign is already there.

As for the Polish characters in the error message, that should work. But make sure you're using a plain-text editor and setting the encoding to UTF-8. I recommend using something like Notepad++ for that.

This worked fine for me (I used Google Translate, so forgive any mistakes in the text):

app.alert("Nieprawidłowy format numeru telefonu.");

Community guidelines

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

/t5/acrobat-discussions/field-format-for-telephone-number/m-p/12961534#M363855 May 23, 2022 May 23, 2022

Copy link to clipboard

quote

As for the Polish characters in the error message, that should work. But make sure you're using a plain-text editor and setting the encoding to UTF-8. I recommend using something like Notepad++ for that.

This worked fine for me (I used Google Translate, so forgive any mistakes in the text):

app.alert("Nieprawidłowy format numeru telefonu.");


By @try67

Yes, I use Notepad ++, the native code editor in DC is one big mistake for me, only the Debugger is surpassed by it .

I have a lot of comments on DC Pro and every 2-3 weeks I am asked for an opinion and a question about the possibility of contact. At the beginning I patiently described my ills and waited for contact, now I don't care, since nobody reads it.

Coming back to the topic, in some forms I have a lot of code with messages for the user and nowhere else has there been a problem with Polish characters, only here. In the worst case, I will edit the message to use words only with Latin alafbet 🙂

Thank you very much for all the answers, they are what I expected !!