Hi, I am new to extjs. I like to know, Is it possible to do dynamic vtype validation like below code...
customRegEX = /^[a-z0-9]/i
customMsg = 'Must be an alphanumeric word'
function ConstructVtype(customRegEX,customMsg)
{
var custExp = customRegEX;
Ext.apply(Ext.form.VTypes, {
AlphaNum: function(v,field) {
return /^[a-z0-9]/i.test(v); // instead of this code
return custExp.test(v);
},
AlphaNumText: customMsg,
AlphaNumMask: custExp
});
}
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 in different way.
hi "Alexander Gyoshev" thanks for ur replay
if i do as per u recommended its working man but i need to change the regexp value dynamically by the textfield change, like the below code how can do this man
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
});
Thanks in advance