stop extjs TextField from accepting blanks and spaces

て烟熏妆下的殇ゞ 提交于 2020-01-02 08:00:11

问题


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,


回答1:


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]+/
});


来源:https://stackoverflow.com/questions/6517460/stop-extjs-textfield-from-accepting-blanks-and-spaces

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!