Skip to main content
Participating Frequently
November 22, 2019
Answered

Remove leading zeros when null

  • November 22, 2019
  • 2 replies
  • 816 views

Hello. I am using a cutom validation script to enter leading zeros in a text box.

 

(function() { var max_len = 9; var val = event.value; while (val.length < max_len) {val = "0" + val;} event.value = val; })();

 

The problem arises when the value is null the field reports "000000000." I would like for it to be blank if null.

 

Any help would be greatly appreciated!

This topic has been closed for replies.
Correct answer try67

Use this:

if (event.value==0) event.value = "";

else {

// rest of code goes here

}

 

2 replies

Participant
October 13, 2020

Hello,

Can please someone help me with this custom script. 

why is that only work on pc, when I open the same PDF with my android Mobile, The Zeros are comming back. 

Thank you. 

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
November 22, 2019

Use this:

if (event.value==0) event.value = "";

else {

// rest of code goes here

}

 

Participating Frequently
November 22, 2019

Perfect!! Thank you so much 🙂