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

How do I set a form field to accept leading zeros in a number?

New Here ,
Aug 27, 2018 Aug 27, 2018

I am trying to create a fillable form using Acrobat Pro DC 2018 for Mac. One of the fields asks for the employee number. Some begin with zero, but after entering the number and saving the form, the leading zero doesn't show up.

24.5K
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

correct answers 1 Correct answer

Community Expert , Aug 27, 2018 Aug 27, 2018

Set the format to None.

Translate
Community Expert ,
Aug 27, 2018 Aug 27, 2018

Set the format to None.

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
New Here ,
Jan 23, 2020 Jan 23, 2020

Sir,

Setting the format to None, the field will also accept alphabets, and then it is not an 'only number' field. The leading zero has to be displayed in Number field alone. In some of the very earlier versions of Excel, it was easy to choose Number format to 'display' or 'do not display' leading zeros.

R G Kulkarni

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 ,
Jan 24, 2020 Jan 24, 2020

PDF and Excel are very different things. If you want the field to only accept numbers, but still allow initial zeros, use the following code as its custom Keystroke script (under Properties - Format - Custom):

 

if (event.change) event.rc = /^\d+$/.test(event.change);

 

Note that using this code you won't be able to enter the negative symbol, or a comma, etc. Only digits.

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
New Here ,
Jan 24, 2020 Jan 24, 2020

Sir,
Greatly honoured to get so fast a reply. The code has worked and I am able
to get the leading zero being displayed in the 'Number' only field.
Thanks and regards,
Saibai40

 

[Private info removed]

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
New Here ,
Aug 25, 2022 Aug 25, 2022

Thank you for this!!

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 ,
Feb 09, 2024 Feb 09, 2024

I have a field set up as a comb for the last four digits of social security numbers and have the same problem with Adobe truncating leading zeros. I tried this code and, while it kept the leading zero (yay!) it also allowed letters to be entered, instead of only allowing numbers. Isn't it possible to have a field only accept numbers AND keep leading zeros? I am NOT a programmer, so I need something very simple.

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 ,
Feb 09, 2024 Feb 09, 2024

The code I posted above will only allow numbers to be entered into the field. Are you sure you used it as described in my 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 Beginner ,
Feb 09, 2024 Feb 09, 2024

I copy/pasted directly from your post, but I figured out an easier way to do it that doesn't involve programming. I selected Format / Special / Arbitrary Mask and entered 9999

 

That did it!

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 ,
Feb 09, 2024 Feb 09, 2024

That works too, but only if the value has a fixed length.

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 ,
Feb 12, 2024 Feb 12, 2024

This field is a fixed length so I am set (at least for this form). 🙂

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
New Here ,
Mar 03, 2024 Mar 03, 2024

God bless you, this scripts worked perfectly 

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
New Here ,
Oct 29, 2024 Oct 29, 2024

I have tried this, and while it does keep the leading 0, it allows letters as well, not just numbers.  I see this answer is a few years old - is there an updated formula to use?

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
New Here ,
Oct 29, 2024 Oct 29, 2024
LATEST

I found another page that specified to enter this in the Custom Keystone Script area, notthe Custom Format Script area; I didn't see that specified here.  Changing the field worked!

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
New Here ,
Feb 03, 2020 Feb 03, 2020

I am very new to applying script to Adobe Acrobat Pro 2017  PDF forms. I have a form where I concatnate two fields (WBSProgram & WBSJobcode) into a third (labeled CompleteWBS) for Work Breakdown Structure (WBS) cost accounting codes. A WBS is alphanumeric, can start with a 0 that must be displayed in the final field.

 

My problem is my final field (CompleteWBS) does not show the 0 in the WBS if it starts with a 0.


this is a correct WBS 

RA.02148956.0123456

my current field would populate this

RA.2148956.23456

 

Is there a script I can apply to still allow letters and also keep leading 0?

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
New Here ,
Feb 03, 2020 Feb 03, 2020

Correction, There are three fields that concatnate into the fourth CompleteWBS. The first is the WBSType 

 

in the above WBS example, the RA is the WBSType

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 ,
Feb 03, 2020 Feb 03, 2020

What script does you use?

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
New Here ,
Feb 04, 2020 Feb 04, 2020
I have three fields (WBSType, WBSProgram and WBSJobCode) that accept user
entry: The WBSType is a dropdown box with options to choose from, the
WBSProgram and WBSJobCode are text fields

I am using JavaScript on blur for the three and javascript. Below are my
script for each field:

*FBMSProjectType -(referenced above as WBSType)*











*//this function popluates the referenced field.function
collatePreSetFieldsTo(populate){ //always overwrite the value in populate
field with these field values var one = this.getField("FBMSProjectType");
var two = this.getField("WBSProgram"); var three =
this.getField("WBSJobCode1"); //concatenate populate.value = one.value +
'.' + two.value + '.' + three.value ;}var five =
this.getField("CompleteWBS1");collatePreSetFieldsTo(five);*










*//this function popluates the referenced field.function
collatePreSetFieldsTo(populate){ //always overwrite the value in populate
field with these field values var one = this.getField("FBMSProjectType");
var two = this.getField("WBSProgram"); var three =
this.getField("WBSJobCode2"); //concatenate populate.value = one.value +
'.' + two.value + '.' + three.value ;}var five =
this.getField("CompleteWBS2");collatePreSetFieldsTo(five);*










*//this function popluates the referenced field.function
collatePreSetFieldsTo(populate){ //always overwrite the value in populate
field with these field values var one = this.getField("FBMSProjectType");
var two = this.getField("WBSProgram"); var three =
this.getField("WBSJobCode3"); //concatenate populate.value = one.value +
'.' + two.value + '.' + three.value ;}var five =
this.getField("CompleteWBS3");collatePreSetFieldsTo(five);*










*//this function popluates the referenced field.function
collatePreSetFieldsTo(populate){ //always overwrite the value in populate
field with these field values var one = this.getField("FBMSProjectType");
var two = this.getField("WBSProgram"); var three =
this.getField("WBSJobCode4"); //concatenate populate.value = one.value +
'.' + two.value + '.' + three.value ;}var five =
this.getField("CompleteWBS4");collatePreSetFieldsTo(five);*


*WBSProgram*











*//this function popluates the referenced field.function
collatePreSetFieldsTo(populate){ //always overwrite the value in populate
field with these field values var one = this.getField("FBMSProjectType");
var two = this.getField("WBSProgram"); var three =
this.getField("WBSJobCode1"); //concatenate populate.value = one.value +
'.' + two.value + '.' + three.value ;}var five =
this.getField("CompleteWBS1");collatePreSetFieldsTo(five);*










*//this function popluates the referenced field.function
collatePreSetFieldsTo(populate){ //always overwrite the value in populate
field with these field values var one = this.getField("FBMSProjectType");
var two = this.getField("WBSProgram"); var three =
this.getField("WBSJobCode2"); //concatenate populate.value = one.value +
'.' + two.value + '.' + three.value ;}var five =
this.getField("CompleteWBS2");collatePreSetFieldsTo(five);*




























































*//this function popluates the referenced field.function
collatePreSetFieldsTo(populate){ //always overwrite the value in populate
field with these field values var one = this.getField("FBMSProjectType");
var two = this.getField("WBSProgram"); var three =
this.getField("WBSJobCode3"); //concatenate populate.value = one.value +
'.' + two.value + '.' + three.value ;}var five =
this.getField("CompleteWBS3");collatePreSetFieldsTo(five);//this function
popluates the referenced field.function collatePreSetFieldsTo(populate){
//always overwrite the value in populate field with these field values var
one = this.getField("FBMSProjectType"); var two =
this.getField("WBSProgram"); var three = this.getField("WBSJobCode4");
//concatenate populate.value = one.value + '.' + two.value + '.' +
three.value ;}var five =
this.getField("CompleteWBS4");collatePreSetFieldsTo(five);WBSJobCode1 - My
form allows up to 4 unique WBSJobCodes. Each has the script below but
different WBSJobCode2, WBSJobCode3, WBSJobCode4//this function popluates
the referenced field.function collatePreSetFieldsTo(populate){ //always
overwrite the value in populate field with these field values var one =
this.getField("FBMSProjectType"); var two = this.getField("WBSProgram");
var three = this.getField("WBSJobCode1"); //concatenate populate.value =
one.value + '.' + two.value + '.' + three.value ;}var five =
this.getField("CompleteWBS1");collatePreSetFieldsTo(five);My final field
where all these concatenate too is labeled CompleteWBS and is Run
JavaScript On Focus//this function popluates the referenced field.function
collatePreSetFieldsTo(populate){ //always overwrite the value in populate
field with these field values var one = this.getField("FBMSProjectType");
var two = this.getField("WBSProgram"); var three =
this.getField("WBSJobCode1"); //concatenate populate.value = one.value +
'.' + two.value + '.' + three.value ;}var five =
this.getField("CompleteWBS1");collatePreSetFieldsTo(five);I also have a
Custom Calculation script in each WBSJobCode field that hides the
CompleteWBS filed if no data is entered into the JobCode fieldvar bReady =
true; if(this.getField("WBSJobCode1").value.length == 0) bReady = false;
else if(this.getField("WBSJobCode1").value.length == 7) bReady = true;
if(bReady) this.getField("CompleteWBS1").display = display.visible;
else this.getField("CompleteWBS1").display = display.hidden*
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 ,
Feb 04, 2020 Feb 04, 2020

Your code is difficult to read.

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
New Here ,
Feb 04, 2020 Feb 04, 2020
I agree and I am sure there is a much more simple way to write the script
to get my end results. It is a form for government use and I cannot send
out the entire form. I will see if I can delete all protected info and
email the portion with the javascript code. Would that work?
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 ,
Feb 04, 2020 Feb 04, 2020

Use a external Javascript editor like notepad++.

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
New Here ,
Feb 04, 2020 Feb 04, 2020
Hi,
If you want the field to only accept numbers, but still allow initial zeros,
use the following code as its custom Keystroke script (under Properties -
Format - Custom):
*if (event.change) event.rc = /^\d+$/.test(event.change);*
Note that using this code you won't be able to enter the negative symbol,
or a comma, etc. Only digits.

Above post is from Adobe Support Community
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
New Here ,
Feb 04, 2020 Feb 04, 2020
Hi all,

My IT department was able to correct my script. Thank you all for the help!!
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 ,
Jun 22, 2020 Jun 22, 2020

thank you

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
New Here ,
Aug 27, 2018 Aug 27, 2018

Thanks ever so much!!! That worked.

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