开发者

ExtJS vtype as a function

开发者 https://www.devze.com 2023-03-25 06:13 出处:网络
Is there any way to test a vType on a value, without it being in a form? Eg I have a custom vtype implemented to do ajax validation, however I would also like to run it against the email vtype, so I

Is there any way to test a vType on a value, without it being in a form?

Eg I have a custom vtype implemented to do ajax validation, however I would also like to run it against the email vtype, so I was hoping to run something inside my custom开发者_StackOverflow社区 vtype along the lines of

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


You could use functions instead of properties, then you could just call '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');
0

精彩评论

暂无评论...
验证码 换一张
取 消