Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

Auto fill zereos

Avatar

Former Community Member

Hi there,

I have a field that has a maximum of 6 numbers. If the user enters less than 6 numbers I would like zereos to fill in the front of the numbers to make the total length 6 numbers long. Is this possible?


Thank you for your help in advance.

Nik

1 Accepted Solution

Avatar

Correct answer by
Level 10

Set the display Pattern for this Numeric field to "num{999999}"..

Thanks

Srini

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Set the display Pattern for this Numeric field to "num{999999}"..

Thanks

Srini

Avatar

Former Community Member

Nik,

If it is a text field you can do something like this to pad the leading zero's.

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


if (this.rawValue != null) {

  var tf = this.rawValue;

  if (tf.length < 6) {

    var diff = 6 - tf.length;

    for (var i=0;i < diff;i++) {

      tf = "0" + tf;

    }

    this.rawValue = tf;

  }

}

If it is a numeric field you can use a display pattern of num{999999}.

Steve