PDA

View Full Version : textField and regular expression?



franklt69
23 Apr 2007, 8:05 AM
Hi I would like to know how work the textField and regular expression, I am doing it:

var phoneNumberExpr = /\(?\d{3}\)?([-\/\.])\d{3}\1\d{4}/;

new Ext.form.TextField({
fieldLabel: 'Telephone ',
name: 'Telephone',
width:240,
regex: phoneNumberExpr,
regexText: 'the format is xxx-xxxx-xxxxx',
allowBlank:false

}),

but never the validations appear, I am missing something

kind regards
Frank

franklt69
23 Apr 2007, 9:22 AM
I did it and work but is always required to make a function validator?

new Ext.form.TextField({
fieldLabel: 'Telephone',
name: 'Telephone',
width:240,
regex: phoneNumberExpr,
invalidText: 'The format is wrong, ie: 305-444-5555',
allowBlank:false,
validator: function(value){
re = new RegExp(phoneNumberExpr);
return re.test(value);

}

}),


kind regards
Frank

jack.slocum
23 Apr 2007, 4:25 PM
Frank, that should work. I'm not sure about the regex though. One thing you may try is VTypes for that. Something like this in your global Ext config file:


Ext.apply(Ext.form.VTypes, {
'phone': function(){
var re = /\(?\d{3}\)?([-\/\.])\d{3}\1\d{4}/;
return function(v){
return re.test(v);
}
}(),
'phoneText' : 'The format is wrong, ie: 305-444-5555'
});

You could even add a second regexp for masking if you wanted to.

Then on your field:


new Ext.form.TextField({
fieldLabel: 'Telephone',
name: 'Telephone',
width:240,
vtype: 'phone',
....
});

franklt69
23 Apr 2007, 4:33 PM
Thanks, Jack Ext1 support masking I means I can type in textField the phone number and appear the chars (305)203-5555 or I type a IP adrress and appear the dot?
192.168.0.2, its supported in ext1?


kind regards
Frank

jack.slocum
23 Apr 2007, 4:36 PM
No, the masking is simple - it just prevents invalid keys from being entered.

franklt69
23 Apr 2007, 4:40 PM
Ok, is there some plan to support it in the future?

kind regards
Frank

jack.slocum
23 Apr 2007, 4:43 PM
It's not planned but it may happen someday. :)