Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Numeric Fields - Exact digits

Avatar

Level 2

Hello, I was wondering if anyone knows how to require a numeric field to be 9 digits, and only 9 digits without any commas or leading zeros. I tried using num{999999999} in the display field but that gives me leading zeros. I want to make the user input only 9 digits or else they cannot submit the form, or an error message pops up, or they cannot go to the next field or something. Any help would be greatly appreciated, I'm new to these programs!

1 Accepted Solution

Avatar

Correct answer by
Level 10

You can use the following display pattern to remove the leading zeros.

          num{zzzzzzzzz}

Place the following code in the change event of the NumericField to restrict the input upto 9 digits with JavaScript as language.    

          if(xfa.event.newText.length >9)xfa.event.change = "";

Place the following code in the Exit event of the field to check the length with JavaScript as language.

          var intValue = this.rawValue.toString();

          if(intValue.length<9){
               xfa.host.messageBox("You need to enter 9 digits");
               xfa.host.setFocus(this.somExpression);
          }

Thanks

Srini

View solution in original post

4 Replies

Avatar

Correct answer by
Level 10

You can use the following display pattern to remove the leading zeros.

          num{zzzzzzzzz}

Place the following code in the change event of the NumericField to restrict the input upto 9 digits with JavaScript as language.    

          if(xfa.event.newText.length >9)xfa.event.change = "";

Place the following code in the Exit event of the field to check the length with JavaScript as language.

          var intValue = this.rawValue.toString();

          if(intValue.length<9){
               xfa.host.messageBox("You need to enter 9 digits");
               xfa.host.setFocus(this.somExpression);
          }

Thanks

Srini

Avatar

Level 2

FANTASTIC! Thank you so much, you are amazing.

Avatar

Level 2

Srini! I need your help again. How can I do the above, but now WITH the capacity for leading zeroes?

Avatar

Level 2

Correction, here are the things I need out of this numeric field:

-only 9 digits, error message if they do not iput total 9 digits and it not allowing more than 9

-allowing leading zeroes, but not autofilling the leading zeroes if they don't input enough. i used your above code, and put num{999999999} in the display pattern but that autofilled zeroes

-no commas in between numbers

THANK YOU!