PDA

View Full Version : Limit for textarea and textfield with RegEx



mcsaygili
23 Sep 2011, 9:56 AM
Hi,
? just wanna try somethink like this,
Input : 3212323

and the textfield or textarea can understand and handle,
the number of input must be min and max 7,
and the users can not be enter [a-zA-Z] just numeric.
So i use, that regex and property,

{
xtype: "textfield",
name: "value",
value: j.phone,
width: 140,
fieldLabel: "Phone Number",
allowBlank: false,
minLength: 7,
maxLength: 7,
maskRe: /^[0-9]{0,7}$/
}

in that case, the user can be entered more then 7 numbers, (unlimited) so how can i solve that problem ?

Colin Alworth
23 Sep 2011, 1:29 PM
This is the forum for Ext GWT, not Ext JS - you might have better luck asking in the JS forums.

droessner
26 Sep 2011, 4:54 AM
Add enforceMaxLength:true

skirtle
26 Sep 2011, 5:41 AM
maskRe is applied to each individual keystroke, not the entire text, so it will only ever be matching against a single character. It also provides no protection against copy/paste or drag/drop of text into the field. To protect against those you'd either use stripCharsRe or a suitable validator.

Have a read of the docs at the top of this page for more details about validation and character masking/stripping:

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.field.Text