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
}
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
}
I'm not familiar with maskRe, but my guess is that you need to anchor the regex:
maskRe: /^\d{0,5}$/
Any reason you're not using the maxLength
config? And to ensure numeric values, you could use a NumberField
instead of a TextField.
If you need more complex regexp, than just list of allowed chars, you need to use 'vtype' http://www.extjs.com/forum/showthread.php?43510-TextField-and-MaskRe&p=206015#post206015
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