How to Restrict User to Put HTML Tag into TextBox

Follow the below code :

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

        function ChkOnlyHtmlTag(event) {

            var keycode;

            //alert("hi");

            if ($.browser.mozilla) {

                if (parseInt(event.charCode) == 0) {

                    keycode = parseInt(event.keyCode);

                }

                else if ((parseInt(event.charCode) != 37) && (parseInt(event.charCode) != 60) && (parseInt(event.charCode) != 62)) {

                    keycode = parseInt(event.charCode);

                }

                else {

                    keycode = 0;

                }

            }

            else {

                if ((parseInt(event.keyCode) != 37) && (parseInt(event.keyCode) != 60) && (parseInt(event.keyCode) != 62)) {

                    keycode = parseInt(event.keyCode);

                }

                else {

                    keycode = 0;

                }

            }

            if (keycode != 0) {

                return true;

            }

            else {

                return false;

            }

        }

        $(function () {

            $('input[type=text]').keypress(function (event) {

                return ChkOnlyHtmlTag(event);

            });

        });

    </script>

Create a aspx page and paste the code in design page. After that place some textboxes into the page. And now run the page. Now try to type some HTML tag into the textboxes. But you cannot type any of the HTML tag into the textboxes. And the above function will work for all textboxes in entire the page.

Next Recommended Reading TextBox validation using JQuery