View Full Version : Force Ext 'numberfield' to validate length of the number before decimal point.

24 Aug 2012, 4:07 AM

I am using ExtJs 4.1.1.

My requirement is to use the text field to get the decimal value[means 123.456 or 123 or 123.000].

I consider Ext 'numberfield' is the right choice, since this has a in build text validation, that will take care of the validation for the text.

I can't force the 'numberfield' to get a defined length of numbers before the decimal point.

i.e for Example:
If precision = 5 and scale = 3 | result should be: 12.345/12.000/0.123

If precision = 3 and scale = 3 | result should be: 0.123

length after decial => scale
length before decimal + length after decimal => precision

While using Ext 'numberfield'
=> precision can be set using the config 'maxLength'
=> scale can be set using the config 'decimalPrecision'

But the problem is the 'numberfield' has no such config for validating the length of the number field before the decimal point [If I am not wrong].

Is there any other way to force the 'numberfield' in the way that it will not allow the user to type more than the specified length before the decimal point.


27 Aug 2012, 1:12 PM
You could assign a maxValue to the numberfield. For example, if you set the maxValue to 99.999, then the user can enter only 2 numbers before the decimal, otherwise the field is marked invalid.