Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extjs input text maskRe

Tags:

regex

extjs

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
}
like image 561
user121196 Avatar asked Apr 08 '10 23:04

user121196


Video Answer


1 Answers

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

like image 75
Anna-Chiara Bellini Avatar answered Nov 15 '22 03:11

Anna-Chiara Bellini