html - Allowing decimal no input to a textbox and validation using javascript -
i have textbox needs accept decimal number input, , disallow other characters , dot entry if more once.i used below approach same
$('#bankemi').keydown(function (e) { var key1 = e.keycode; if (key1 == 190 || key1 == 110) { var s = $('#bankemi').val(); if (s.indexof('.') > - 1) { e.preventdefault(); return false } return true } if (key1 == 13 || key1 == 8 || key1 == 9 || key1 == 46 || (key1 >= 35 && key1 <= 40)) { return true } if (e.shiftkey || e.ctrlkey || e.altkey) { e.preventdefault() } else { var key = e.keycode; if (!((key >= 48 && key <= 57) || (key >= 96 && key <= 105))) { e.preventdefault() } } }) }); bankemi- input box. need support number of kind 4100.50 haven't put restriction on decimal places of now, cause round value 2 decimal places later in calculation. if user inputs 4100.524 rounded , used. can there more simpler way handle this?
you should use regex perform task. http://www.w3schools.com/jsref/jsref_obj_regexp.asp
Comments
Post a Comment