Skip to main content
Participant
May 12, 2017
Question

How do you get the zero to stay in a field after you click out of it.

  • May 12, 2017
  • 1 reply
  • 370 views

If my user enters a number that starts with zero, the zero disappears once they click out of the field.  I need for the zero  to stay.  For example, they enter 09876, only 9876 shows

This is the script that I have so far in it.

.

var desiredLength = 9; // the number of digits the user should enter

event.rc = true;
if (event.value && event.value.length!=desiredLength) {
    app.alert("You must enter exactly " + desiredLength + " digits.");
    event.rc = false;
}

This topic has been closed for replies.

1 reply

Inspiring
June 29, 2017

The over whelming number of programs and applications do not show leading zeros. Leading zeros are generally associated with character strings and need special formatting.

Working within a field, the event.value will retain the leading zeros. To read the value of a different field you need to use the valueAsString method. One can force the value to have leading zeros by using the util.printf method. You should be aware that the format for a field only affects the displayed value and not the actual value of the field.