Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

leading zero

Not applicable
what's the best way to keep the leading zeros of a numeric field?



ie. if user enters "000123"

it shows "000123" instead of "123"
5 Replies
pguerett
Level 10
Level 10
Unsure of which way you want to go. You say you want to keep the leading zeros but your example removes them. In either case you need to set a validation pattern. There are 4 times a pattern is applied:



Display - for what is viewed on screen

Edit - for what the user types in

Validation - for what the field is checked against

Data - for what is placed in the data dom



In your case a 9 indicates that a number needs to be present and a z means you want leading zeros. So if I have a Display pattern of 999999 then I will display 6 digits (zeros are digits). If I also add an edit pattern of zzz999 then the user can enter 123 but 000123 will be displayed. You can adjust the patterns to give you what you want.
Not applicable
Paul, thanks for suggestions, I tried it but it didn't give me the desired results.



This is what I want:



a Numeric field,

user can enter any number of numeric digits,

when he enters "000000123", I want it to display as "000000123";

when he enters "1234567", I want it to display as "1234567";

when he enters "0789", I want it to display as "0789";

...etc



ie. no matter how many leading "0"s he enters, whatever he entered will be displayed as is, I don't want the leading "0"s be chopped off.



what Patterns can give me that effect?



thanks
pguerett
Level 10
Level 10
The issue is that you are allowing any length of entry hence there is no pattern (a defined length and structure that the input needs to follow - i.e. a social security number - always 9 digits)



What if we captured the input as text then wehn we want o use it convert to an int. Then whatever they type will be displayed and when you want to use it for calcs we turn it into an integer.
wandererers
Level 1
Level 1

Hello,

I am having the same problem.  I need to retain an ID number that always starts with 2 0s and is 9 digits long as in 009999999.  I have tried the numerous num {99...} combinationz with z's and nums and nothing has worked.  However, you mentioned saving as 'text' and converting to 'int'.  How do I do that?  Any help is greatly appreciated.

Thanks

radzmar
Level 10
Level 10

Use this pattern for this purpose.

num{'00'9999999}

still-learning-
Level 1
Level 1

So If I wanted 4 digits and retain leading zeros in the display I would use num{'000'9}?

Where does that go on the Validate tab in the custom validation script?

_Bruce_Robertson
Level 10
Level 10

Hi,

Try a display pattern of;

num{'000'9}|num{'00'99}|num{'0'999}|num{9999}

One digit will match the first pattern and add the '000' string, etc

Regards

Bruce

still-learning-
Level 1
Level 1

Thanks Bruce,

Someone else gave me the following and it works just fine:

if (event.value) {

event.rc = /^\d{5,7}$/.test(event.value);

if (!event.rc) app.alert("You must enter between 5 and 7 digits.");

}

Do you know where I can read up on: /^\d{5,7}$/.test(event.value)

Regards,

Jeff

Jeff Hill

Lions Clubs International

MSC Business Analyst

630-468-6759

Celebrating 100 Years of Service

Lions100.org<http://lions100.lionsclubs.org/EN/index.php>

“We Serve”

<http://lionsclubs.org/blog/>[ico-fb]<http://www.facebook.com/lionsclubs>[ico-yt]<http://www.youtube.com/user/lionsclubsorg> <http://twitter.com/lionsclubs> <http://www.linkedin.com/company/33854> <http://www.flickr.com/photos/lionsclubsorg/> <http://pinterest.com/lionsclubs/> <http://instagram.com/lionsclubs>

_Bruce_Robertson
Level 10
Level 10

Hi,

Adobe Reader uses SpiderMonkey JavaScript, so you could start with RegExp.prototype.test() - JavaScript | MDN 

There will be some things on that website that don't apply as Adobe Reader is still using a fairly old version 1.7 or 1.8

Regards

Bruce

Liefie2000
Level 4
Level 4

If you use text, then they can put alpha characters in that field where he probably only wants numeric input.

Steve_L_Walker
Level 10
Level 10

There's always code. For a text field with a max length of 9.

// form1.page1.tf-numeric-only::exit - (JavaScript, client)

if (!(this.isNull)) {

          var tf = this.rawValue;

          // \D to match any character NOT in the range 0 - 9

          var regExp = /\D/;

          if (regExp.test(tf)) {

   xfa.host.messageBox("The field must be numeric.");

          }

          else {

    if (tf.length != 9) {

      xfa.host.messageBox("The field must contain 9 digit.");

    }

    else {

      if (tf.substring(0,2) != "00") {

        xfa.host.messageBox("The field must start with '00'.");

      }

    }

          }

}

Steve