PDA

View Full Version : Text preventing non numeric characters



thesuite
17 Apr 2011, 6:00 AM
Hi All,

I have a text field and have implemented the keyup event, anyone got an idea on how I would prevent non numeric characters in the field.

As always, any help would be appreciated

Thanks

thesuite
17 Apr 2011, 8:11 AM
Hi All,

Found the solution.


var pagenumber = new Ext.form.Number(
{
itemId: "PageNo",
width: 80,
value: "1/" + nopages.innerHTML,
ui: "normal",
listeners: {
focus: function (txt, e) {
txt.setValue('');
},
blur: function (txt, e) {
txt.setValue('1/2');
},
keyup: function (f, e) {
var charCode = (e.which) ? e.which : event.keyCode;
var values = f.getValue();
if (charCode > 31 && (charCode < 48 || charCode > 57))
f.setValue(values.substr(0, values.length - 1));

}
}
});