Textbox Width Manipulation – Not working on mobile

0

I want restrict the space in empty text box and text-area box below Code is not working in mobile its working in desktop please check and help on this

<html>

<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script>
    $(document).ready(function() {
        $("input[type=text],textarea").keypress(function(e) {
            if(e.which === 32 && !this.value.length) {
                return e.which !== 32;
            }
        });
    });
    </script>
</head>
<input type="text" maxlength='25'>
<textarea></textarea>

</html>