2012-06-01 25 views

回答

1

使用autoStripChars並從initComponent中允許刪除連字符。正確的代碼如下。

autoStripChars: true, 
initComponent: function() { 
    var me = this, 
     allowed; 

    me.callParent(); 

    me.setMinValue(me.minValue); 
    me.setMaxValue(me.maxValue); 

    // Build regexes for masking and stripping based on the configured options 
    if (me.disableKeyFilter !== true) { 
     allowed = me.baseChars + ''; 
     if (me.allowDecimals) { 
      allowed += me.decimalSeparator; 
     } 
/* removed code 
    if (me.minValue < 0) { 
      allowed += '-'; 
     } 
*/ 
     allowed = Ext.String.escapeRegex(allowed); 
     me.maskRe = new RegExp('[' + allowed + ']'); 
     if (me.autoStripChars) { 
      me.stripCharsRe = new RegExp('[^' + allowed + ']', 'gi'); 
     } 
    } 
} 
0

您也可以使用帶有maskRe config的常規Textfield。

maskRe: /[0-9]/ 
0

與@ lagnat的回覆類似,這是一個白名單,您可以使用stripCharsRe config黑名單字符。

stripCharsRe: /-/ 

如果您想要限制負值。

minValue: 0 
0
{ 
    minValue: 0, 
    autoStripChars: true, 
    allowExponential: false 
} 
相關問題