Search This Blog

Wednesday, August 31, 2016

SharePoint number column should accept only numbers



Solution:

<script type="text/javascript">
        $(document).ready(function () {
            $('input[Title="ColumnName"]').keydown(function (e) {
                var keyCode = e.which; // Capture the event
                //190 is the key code of decimal if you dont want decimals remove this condition keyCode != 190
                if (keyCode != 8 && keyCode != 9 && keyCode != 13 && keyCode != 37 && keyCode != 38 && keyCode != 39 && keyCode != 40 && keyCode != 46 && keyCode != 110 && keyCode != 190) {
                    if (keyCode < 48) {
                        e.preventDefault();
                    }
                    else if (keyCode > 57 && keyCode < 96) {
                        e.preventDefault();
                    }
                    else if (keyCode > 105) {
                        e.preventDefault();
                    }
                }
            });
        });
       
</script>

No comments:

Post a Comment