PDA

View Full Version : format number string



quinta
28 Dec 2010, 11:19 AM
hello all:

I need to format the content of a textfield (alwais number) like this: 9 999 999

Anybody can help , please???

Thanks in advance

sideeque
28 Dec 2010, 12:31 PM
You might need to have your won regular expression for the format. try googling it if somebody already have for your format...

Then Create a Vtype something like below.


Ext.apply(Ext.form.VTypes, {
'phone': function(){
var re = /^(\d{3}[-]?)(\d{3}[-]?){1,2}(\d{4})$/;
return function(v){
var retval = re.test(v);
if (v == '') {
return true;
}
else {
return retval;
}
}
}(),
'phoneMask': /[\d-]/,
'phoneText': 'Not a valid phone number. Must be in the format xxx-xxx-xxxx (Dashes optional)'
});

And use something like below in text field


var phone = new Ext.form.TextField({
fieldLabel: 'Phone Number',
name: 'phone',
value: '',
labelAlign: 'left',
vtype: 'phone',
});

quinta
29 Dec 2010, 2:26 AM
Thanks for your reply, I'll try it.

aramaki
29 Dec 2010, 2:29 AM
You can use NumberField editor, also, if you need to specify template, it`s possible to set regexp by regex: /[...]/

quinta
30 Dec 2010, 3:37 AM
Could you put an example about the numberfield editor, please???

Thanks