Highlighted

leading zero

Avatar

Guest

13-08-2008

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"

Replies

Highlighted

pguerett

14-08-2008

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.
Highlighted

Avatar

Guest

14-08-2008

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
Highlighted

pguerett

14-08-2008

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.
Highlighted

wandererers

13-10-2010

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

Highlighted
Highlighted

Steve_L_Walker

31-10-2011

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

Highlighted

still-learning-

07-12-2016

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?