PDA

View Full Version : Can Dynamic Vtype validation Done(like below code) in extjs



27 Oct 2010, 7:03 AM
Hi,
I am new to extjs. I like to know, Is it possible to do dynamic vtype validation like below code...

function ConstructVtype()
{
var customRegEX = this.customRegEX; ////^[a-z0-9]/i,
customMsg =this.customErrorMsg;

Ext.apply(Ext.form.VTypes, {
AlphaNum: function(v,field) {
return customRegEX.test(v);
},
AlphaNumText: customMsg,
AlphaNumMask: customRegEX
});

}


var txt = new Ext.form.TextField({
renderTo:Ext.getBody(),
validator :ConstructVtype,
fieldLabel: 'Telephone',
name: 'Telephone',
vtype:'AlphaNum',
id:'test1',
customRegEX:'/^[a-z0-9]/i',
customErrorMsg:'Must be an alphanumeric word',
width:240

});

var txt2 = new Ext.form.TextField({
renderTo:Ext.getBody(),
validator :ConstructVtype,
fieldLabel: 'Telephone',
name: 'Telephone',
vtype:'AlphaNum',
id:'test2',
customRegEX:'/^[a-zA-Z]/i',
customErrorMsg:'Must be an alphabets',
width:240

});

But i am getting error (Object does not support this method) in the line "return custExp.test(v);"
since there is no method called test in the object(custExp)

Is it possible to typecast 'custExp' to that object which hold the test method,

IF the above point is possible means pls provide that object type and how to typecast ?
OR
Provide How can i achieve this functionality


Thanks in advance