Wednesday, 24 April 2013

Blocking HTML Tags OR Allow only one HTML Tag for Text box using java script


Blocking HTML Tags OR Allow only one HTML Tag for Text box using java script

Script :-

<script type="text/javascript">
        function ScriptTagsValidation(e, objCtrl) {
            var key = window.event ? e.keyCode : e.which;
            var keychar = String.fromCharCode(key);
            var PreviousValue = objCtrl.value;
            var containchars;
            var count = 0;
            if (keychar == "<" || keychar == ">") {
                var Tags = "<>";
                for (var d = 0; d < PreviousValue.length; d++) {
                    containchars = PreviousValue.charAt(d);
                    if (Tags.indexOf(containchars) != -1) {
                        count++;
                    }
                }
                if (count == 1) {
                    return false;
                }
            }
            return true;
        }
    </script>

Design :-

<asp:TextBox ID="TextBox1" runat="server" onkeypress="return ScriptTagsValidation(event,this);"></asp:TextBox>

Related Posts:

  • Word Documents and Excel Documents in IFRAME In this below example we are converting word OR excel document to HTML. In this case we are converting and giving converted HTML file as ""src"" to ""iframe"". Step By Step Procedure : 1)First step is create one… Read More
  • Word document in iframe This is screen shot for iframe.Here In the below Screenshot iframe viewing the word document in the form of html. so i am giving html to the Iframe src. Iframe can view excel,csv,pdf,text file… Read More
  • Replace characters in javascript In server side we have "Replace" method to replace the characters in a string but on javascript replace method will be not useful in certain cases instead of that we can do for loop to replace the particular characters and g… Read More
  • How to Call Method Or Function Or Button From Java Script Call Method Or Function Or Button From Java Script                     Actually we can call button from java script and it will lead the post back also … Read More
  • Image Mouse Hover in asp.net To show image in particular div when mouse hover on the image using asp.net   Script <script type="text/javascript" language="javascript">         function ShowToolTip(con) {   &n… Read More

0 comments:

Post a Comment