In Ext JS, the following maskRe
doesn't work in that it doesn't put the restriction of max 5 characters on the text field, why?
{
xtype: 'textfield',
fieldLabel: '* Zip Code',
allowBlank: false,
maskRe: /\d{0,5}/i
}
Made the same validation yesterday and had the similar problems :-)
You're mistaking maskRe with regex. regex will validate the whole string, maskRe will filter char input. therefore specify the full validation regex in regex, and only the character class with allowed chars in maskRe - which is not required but helpful if you don't want users to type AAAAA just to be told that it's wrong -.
I would not use NumberField instead, because what you are trying to validate is not really a number, but rather a numeric code, and negative numbers are not allowed. Also, instead of allowing 0-5 chars, why won't you allow exactly 5? This also does not allow for blanktext, so allowBlank:false is not necessary.
Try this
regex: /^\d{5}$/i,
maskRe: /\d/i
HTH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With