Menu ▼

Previous Next

String trim function in javascript :

Example:
-------------


Code Sample :

<html>

<head>

    <title>String trim function in JavaScript</title>

    <script language="Javascript" type="text/javascript">

        String.prototype.trim = function () { return this.replace(/^\s+|\s+$/g, ''); };

 

        function trimval(t) {

            try {

                document.getElementById("txtout").value = t.value.trim();

            }

            catch (err) {

                alert(err.Description);

            }

        }

 

    </script>

</head>

<body>

    <table align="center">

        <tr>

            <td>

                <input type="text" onkeyup="trimval(this);" />

            </td>

        </tr>

        <tr>

            <td>

                <input type="text" id="txtout" />

            </td>

        </tr>

    </table>

</body>

</html>

 

Previous Next




Search dotnetlearners.com