Top Ad unit 728 × 90

Allow hyphen and floating numbers in keypress event in jquery

If you want to bind the textbox only takes input the numbers, dot, hyphen means minus sign then you can use this function. This script is already tested and works fine.



$('input.numbers').keypress(function(event) {
           if (event.which != 46 && event.which != 45 && event.which > 31
           && (event.which < 48 || event.which > 57))
           return false;

           if(event.which == 46
           && $(this).val().indexOf('.') != -1) {
                event.preventDefault();
        }
  });



It will take only one dot(.). Sometimes developer forgets to add left arrow, right arrow, backspace and delete key. So, don't worry about it. Just try the above script. It may resolve your problems. If it works for you then just give comments. Thanks!
Allow hyphen and floating numbers in keypress event in jquery Reviewed by Ashok Sen on 09:32:00 Rating: 5
All Rights Reserved by ASENwebmedia © 2014 - 2015
Powered By Blogger, Developed by Asenwebmedia

Contact Form

Name

Email *

Message *

Powered by Blogger.