EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Aod47 on June 28, 2020, 03:13:49 AM



Title: How to set maxlength of searchbox and accept only numeric?
Post by: Aod47 on June 28, 2020, 03:13:49 AM
I tried code but not work.

Code:
$('#sb').searchbox('textbox').attr('maxlength', 10);

And how to set searchbox accept only numeric.


Thank you.


Title: Re: How to set maxlength of searchbox and accept only numeric?
Post by: jarry on June 30, 2020, 07:20:05 PM
Please try this code.
Code:
$('#sb').searchbox({
inputEvents: {
keypress:function(e){
var target = e.data.target;
var tmp = $('<span></span>');
tmp.html(String.fromCharCode(e.which));
var c = tmp.text();
tmp.remove();
if ('0123456789'.indexOf(c) >= 0){
return true;
} else {
return false;
}
}
}
})
$('#sb').searchbox('textbox').attr('maxlength',10);


Title: Re: How to set maxlength of searchbox and accept only numeric?
Post by: Aod47 on July 05, 2020, 11:43:36 PM
Work great!  ;D Thank you