Skip to main content
anilk74395976
Participant
September 26, 2016
Answered

I need to make a field only accept maximum 6 digit numbers, should not truncate any leading 0

  • September 26, 2016
  • 2 replies
  • 1700 views

I tried with builtin in number filed option but it's truncating the leading zeros,

I need to make the field only accept maximum of 6 digits, should not truncate any other zeros.

Please help

This topic has been closed for replies.
Correct answer try67

Set the Format option to None and use this code as the custom validation script (you can also set the maximum number of characters to 6, if you wish):

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

2 replies

Participating Frequently
December 7, 2016

I need to have them enter an ID number between 5 and 7 digits long

- and I need to guarantee its numbers not letters

- and I need to allow leading zeros to display as well.

I currently have a format set to number and a validation script of:

---

var minLength = 5; // the minimum number of digits the user should enter

var maxLength = 7; // the maximum number of digits the user should enter

event.rc = true;

if (event.value && (event.value.length<minLength || event.value.length>maxLength))

{

   app.alert("You must enter between " + minLength + " and " + maxLength  + " digits.");

   event.rc = false;

}

---

This takes car of 5-7 digits and guarantees its a number but it still suppresses leading zeros in the display.

Any ideas?

try67
Community Expert
Community Expert
December 7, 2016

You can't use the Number format if you want leading zeros. Set it to None and replace your validation script with this:

if (event.value) {

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

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

Participating Frequently
December 8, 2016

That worked great thanks!

Where can I go to read up on what /^\d{5,7}$/ actually means?

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
September 26, 2016

Set the Format option to None and use this code as the custom validation script (you can also set the maximum number of characters to 6, if you wish):

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