EasyUI Forum
April 25, 2024, 12:58:37 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: How to set maxlength of searchbox and accept only numeric?  (Read 4101 times)
Aod47
Jr. Member
**
Posts: 81


View Profile
« 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.
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 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);
Logged
Aod47
Jr. Member
**
Posts: 81


View Profile
« Reply #2 on: July 05, 2020, 11:43:36 PM »

Work great!  Grin Thank you
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!