maskRe ExtJS 6.0.2

maskRe ExtJS 6.0.2

我只是想限制用户输入 1 到 6 之间的数字。所以我的代码是:

{
        xtype            : 'textfield',
        id               : 'NUMBER',
        width            : '100%',
        fieldLabel       : "NUMBER",
        dataIndex        : 'NUMBER',
        maxLength        : 1,
        value            : 0,
        regex            : /[0-6\/]/,
        maskRe           : /[0-6]/,
        enforceMaxLength : true,
        readOnly         : true,
        mandatory        : true,
}

出于某种原因,我可以输入从 1 到 9 的任何数字(尽管我收到无效表单错误)。此外,由于某种原因起始值为 0,我可以在他之前添加一个数字,例如允许我输入“90”。

所以我的最后一个问题是,"Why doesn't my "maskRe“工作正常”?

您正在寻找:

{
  xtype: 'numberfield',
  label: 'Age',
  minValue: 1,
  maxValue: 6,
  name: 'age'
}

关于maskRe,他们说:

maskRe : RegExp An input mask regular expression that will be used to filter keystrokes > (character being typed) that do not match. Note: It does not filter characters > already in the input.

所以 /[1-6]/ 的 maskRe 只会让用户输入 1 到 6 个字符,但不会使已经输入的 0 无效,也不会施加长度限制。

你的代码,没有 readOnly:true,对我来说是 fiddle;所以我不确定为什么它对你不起作用。

You can find the fiddle here;请注意,我仅在最近的 Chrome 中进行了测试。