验证numberfield的值,而不是长度

Validate NumberField's value, not length

本文关键字:numberfield 的值 验证      更新时间:2023-09-26

Model:

Ext.define('Web.model.Server', {
    extend : 'Ext.data.Model',
    idProperty : 'guid',
    fields : [ {
        name : 'guid',
        type : 'string'
    },/* ... */ {
        name : 'timeout',
        type : 'integer'
    }],
    validators : {
        timeout : {
            type : 'length',
            min : 10,
            max : 60
        }
    }
});

每当我将timeout设置为任何值(例如40)并调用.isValid()时,它返回false并表示timeout: Length must be between 10 and 60。换句话说,它将值的长度验证为String,而不是数字本身的值。

我在文档中找不到关于验证number值的任何内容:5.1.1 ext验证器文档没有广泛编写。

如何验证数字的值,而不是长度?

尝试使用范围验证器:

validators: {
    timeout: {
        type: 'range',
        min: 10,
        max: 60
    }
}