jquery: numeric input only, but also restrict number of characters -


i using following jquery function allow numeric input. works fine, client wants limit input 8 numeric values. there away, using code below restrict number of characters?

$(document).ready(function () {     $('input.numberinput').bind('keypress', function (e) {         return !(e.which != 8 && e.which != 0 &&                 (e.which < 48 || e.which > 57) && e.which != 46);     }); });​ 

thank in advance.

try this

$(document).ready(function () { $('input.numberinput').bind('keypress', function (e) {    if(this.value.length>= 8)            {             alert('maximum limit 8'); return false;           }     return !(e.which != 8 && e.which != 0 &&             (e.which < 48 || e.which > 57) && e.which != 46); }); 

});​


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -