PDA

View Full Version : VType not working



oneofthelions
11 Feb 2011, 2:56 AM
I have a text filed




var issueNoField = new Ext.form.TextField({
fieldLabel:'Issue No',
width: 120,
vtype: 'hyphen'

});


I am using VType to check the text




Ext.apply(Ext.form.VTypes, {
hyphenText:"Number and hyphen",
hyphenMask:/[\d-]/, //To allow digits and '-' in the text field.
//This is working

hyphenRe:/^\d+-\d{1,2}$/, //To allow n digits, then '-', then 1 or 2
//digit(s). This is not working

hyphen:function(v){
return hyphenRe.test(v);
}
});


Please correct my vtype to allow n digits, then '-' hyphen, then 1 or 2 digit(s). Why is hyphenRe not being called. Is there any other way to do this?

Condor
11 Feb 2011, 4:16 AM
Shouldn't that be:

Ext.apply(Ext.form.VTypes, {
hyphenText: "Number and hyphen",
hyphenMask: /[\d\-]/, \\ don't forget to escape the '-'
hyphenRe: /^\d+-\d{1,2}$/,
hyphen: function(v){
return Ext.form.VTypes.hyphenRe.test(v);
}
});

oneofthelions
13 Feb 2011, 11:35 PM
It only Mask the text field to allow digits and hyphen. But the regex is not checked to allow only one hyphen and at most two digits after hyphen. Currently the user can enter as many digits and hyphens.

Please suggest

Condor
17 Feb 2011, 2:19 AM
Ext doesn't restrict what you type. It only marks the field invalid and doesn't submit if you entered something that doesn't match the mask.

oneofthelions
17 Feb 2011, 9:47 PM
Thanks to the information on Mask, I shall keep in mind.
But I called my function as you mentioned.


return Ext.form.VTypes.hyphenRe.test(v); But this doesn't work. This return to the function is not happening?

Condor
18 Feb 2011, 12:07 AM
This return to the function is not happening?

Do you mean the function never gets called or that the field isn't marking invalid when you type something that doesn't match the mask?