user121196
user121196

Reputation: 31060

extjs input text maskRe

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
}

Upvotes: 5

Views: 27513

Answers (4)

Brian Moeskau
Brian Moeskau

Reputation: 20431

Any reason you're not using the maxLength config? And to ensure numeric values, you could use a NumberField instead of a TextField.

Upvotes: 6

Anna-Chiara Bellini
Anna-Chiara Bellini

Reputation: 1020

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

Upvotes: 7

MarkB
MarkB

Reputation: 1

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

Upvotes: 0

Alan Moore
Alan Moore

Reputation: 75262

I'm not familiar with maskRe, but my guess is that you need to anchor the regex:

maskRe: /^\d{0,5}$/

Upvotes: 1

Related Questions