Ali
Ali

Reputation: 8100

stop extjs TextField from accepting blanks and spaces

This is my textfield

siteNameField = new Ext.form.TextField({
id: 'siteNameField',
fieldLabel: 'Site Name',
maxLength: 50,
allowBlank: false,
anchor:'-15',
xtype:'textfield',
maskRe: /([a-zA-Z0-9\s]+)$/

});

As you can see it already has a check for blanks. But text field accepts space and I don't want that. I want no blank fields ... anything other than 'ONLY' spaces is acceptable .

Here is the FormPanel Code

voiceSiteCreateForm = new Ext.FormPanel({
    labelAlign: 'top',
    bodyStyle:'padding:5px',
    width: 600,        
    items: [{
        layout:'column',
        border:false,
        items:[{
            columnWidth:0.5,
            layout: 'form',
            border:false,
            //items: [siteNameField, siteNumberField,queueNameField,notifyFreqField,notifyStatusField]
            items: [siteNameField, siteNumberField]
        }]
    }],
buttons: [{
  text: 'Save and Close',
  handler: createSite
},{
  text: 'Cancel',
  handler: function(){
    // because of the global vars, we can only instantiate one window... so let's just hide it.
    siteCreateWindow.hide();
  }
}]
});

Please help,

Upvotes: 3

Views: 16500

Answers (1)

evilcroco
evilcroco

Reputation: 531

Remove maskRe and use regex. Eg:

siteNameField = new Ext.form.TextField({
  id: 'siteNameField',
  fieldLabel: 'Site Name',
  maxLength: 50,
  allowBlank: false,
  anchor:'-15',
  xtype:'textfield',
  regex: /[a-zA-Z0-9]+/
});

Upvotes: 11

Related Questions