web123456

js doesn't allow negative numbers in the input box, and can't exceed two decimals

  • function noNumbers(e){
  • var keycode = window.event ? e.keyCode : e.which;
  • The //Internet Explorer/Chrome browsers use to retrieve pressed characters, while Netscape/Firefox/Opera etc. use .
  • var keychar = String.fromCharCode(keycode);//fromCharCode: convert Unicode code to a character.
  • if(keycode >= 48 && keycode <= 57){ // Numeric keypad code: 0-9
  • e.returnValue = true;
  • }else if(keycode >=96 && keycode <= 105){ //Small keypad numeric codes: 0-9
  • e.returnValue = true;
  • }else if(keycode == 8 || keycode == 46){ // Delete key and delete
  • e.returnValue = true;
  • }else if(keycode == 109 || keycode == 189){ //Negative sign
  • e.returnValue = true;
  • // Other than that, no other inputs are allowed
  • }else{
  • e.returnValue = false;
  • }
  • }