Thursday, April 9, 2015

Jquery check textbox entered value is decimal with single dot for multiple textboxes

 <script type="text/javascript">

        $('input[id$=Text1],input[id$=Text2],input[id$=Text3]').keypress(function (event) {

            return isNumber(event, this)

        });


        // THE SCRIPT THAT CHECKS IF THE KEY PRESSED IS A NUMERIC OR DECIMAL VALUE.
        function isNumber(evt, element) {

            var charCode = (evt.which) ? evt.which : event.keyCode

            if (
                (charCode != 45 || $(element).val().indexOf('-') != -1) &&      // “-” CHECK MINUS, AND ONLY ONE.
                (charCode != 46 || $(element).val().indexOf('.') != -1) &&      // “.” CHECK DOT, AND ONLY ONE.
                (charCode < 48 || charCode > 57))
                return false;

            return true;
        }
    </script>

No comments:

Post a Comment