View Full Version : Leading zeros in numberfield (Ext.form.field.Number) in 4.x

9 Nov 2011, 11:54 AM
I'm trying to extend the numberfield to have leading zeros and wanted to see if anybody has done this before.
I would like to have a hour, minute, and seconds fields that allow the user to enter a single number and the form field format the entry with leading zero. (i.e. The user enters 5 and tabs to the next field then the UI would show 05)

I've search the forum and found some related post but none for the extjs 4.x.

Here are some previous posts...



9 Nov 2011, 12:08 PM
both approaches should also work for ext 4. in case you want to migrate my ux to ext 4, you will need to take a look at the new setValue method and adjust changes (should be quite easy).

using a textfield with the maskRe - config set to


is also ok. you can set a listener on the blur event and change the value of the field.

9 Nov 2011, 8:33 PM
Maybe this would help?


It was intended to be used for currencies but you should be able to tweak the format to whatever you want.

5 Aug 2013, 9:06 AM
add to number field config:

valueToRaw: function (value)
return (value < 10 ? '0' : '') + value; // any string conversion

19 Aug 2013, 2:59 PM
That solution doesn't handle the general case of an arbitrary length number field that needs to preserve leading zeroes. Another way to think of this problem is you want to preserve the number of significant digits to the left of the decimal.