ExtJS vtype作为函数

时间:2011-08-05 06:24:10

标签: extjs

有没有办法在值上测试vType,而不是在表单中?

例如,我有一个自定义vtype实现了ajax验证,但我也想对电子邮件vtype运行它,所以我希望在我的自定义vtype中运行一些内容

validate('abc@de.ce','email');

1 个答案:

答案 0 :(得分:5)

您可以使用函数而不是属性,然后您可以调用'em:

Ext.apply(Ext.form.VTypes, {

    // Validates an ajax thingy
    ajax: function(v) {
        // validate against email VType
        return Ext.form.VTypes.email(v);
    },

    // Override the default Ext function, to allow oddly-placed hyphens
    email: function(v) {
        var regex = /^[-\w][-+\.\w]*@[-\w\.]+\.[A-Za-z]{2,4}$/;
        return regex.test(v);
    }
}

Ext.form.VTypes.ajax('abc@de.ce');