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

How to Pad a Number with Leading Zero

Community Beginner ,
Dec 11, 2022 Dec 11, 2022

Copy link to clipboard

Copied

For example,

I have 10 numbers blank _ _ _ _ _ _ _ _ _ _

When I input "123456" , I want the blank fill with "0000123456".

How to do this on Prepare Form?

TOPICS
How to , JavaScript , PDF forms

Views

114

Translate

Translate

Report

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 ,
Dec 12, 2022 Dec 12, 2022

Copy link to clipboard

Copied

As validation script of field where you input number use this:

function zeroes(number, length) {
var str = "" + number;
while(str.length < length){
str = "0" + str;}
return str;}
if(event.value != "")
event.value = zeroes(event.value,10);

Votes

Translate

Translate

Report

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 ,
Dec 12, 2022 Dec 12, 2022

Copy link to clipboard

Copied

LATEST

Here's a slightly more compact method

 

event.value = ("0000000000" + event.value).slice(-10);

 

or

 

event.value = util.printf("%010d", event.value);

 

This could be used as either a format or validation script

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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