Friday 2 August 2013

Restriction for entering special character in textbox using javascript

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <style type="text/css">
        body
        {
            font-size: 9pt;
            font-family: Arial;
        }
    </style>
</head>
<body>
    Alphanumeric value:
    <input type="text" id="text1" onkeypress="return IsAlphaNumeric(event);" ondrop="return false;"
        onpaste="return false;" />
    <span id="error" style="color: Red; display: none">* Special Characters not allowed</span>
    <script type="text/javascript">
        var specialKeys = new Array();
        specialKeys.push(8); //Backspace
        specialKeys.push(9); //Tab
        specialKeys.push(46); //Delete
        specialKeys.push(36); //Home
        specialKeys.push(35); //End
        specialKeys.push(37); //Left
        specialKeys.push(39); //Right
        function IsAlphaNumeric(e) {
            var keyCode = e.keyCode == 0 ? e.charCode : e.keyCode;
            var ret = ((keyCode >= 48 && keyCode <= 57) || (keyCode >= 65 && keyCode <= 90) || (keyCode >= 97 && keyCode <= 122) || (specialKeys.indexOf(e.keyCode) != -1 && e.charCode != e.keyCode));
            document.getElementById("error").style.display = ret ? "none" : "inline";
            return ret;
        }
    </script>
</body>
</html>

Monday 29 July 2013

Restriction enter only numeric value in textbox using jquery


<td class="style3">
                    <asp:TextBox ID="TextBox6" runat="server" class="numeric"></asp:TextBox>
                    <span class="error" style="color: Red; display: none">* Input digits (0 - 9)</span>
                    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

    <script type="text/javascript">

        var specialKeys = new Array();

        specialKeys.push(8); //Backspace

        $(function () {

            $(".numeric").bind("keypress", function (e) {

                var keyCode = e.which ? e.which : e.keyCode

                var ret = ((keyCode >= 48 && keyCode <= 57) || specialKeys.indexOf(keyCode) != -1);

                $(".error").css("display", ret ? "none" : "inline");

                return ret;

            });

            $(".numeric").bind("paste", function (e) {

                return false;

            });

            $(".numeric").bind("drop", function (e) {

                return false;

            });

        });

    </script>

                </td>

Saturday 27 July 2013

Create a Indian flag in c#


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int a;
            for (int i = 0; i < 25; i++)
                Console.Write(" ");
            for (int i = 0; i < 15; i++)
                Console.Write("_");
            Console.WriteLine();
            for (a = 1; a < 40; a++)
            {
                for (int i = 0; i < 23; i++)
                    Console.Write(" ");
                Console.Write("||");
                if (a == 6 || a == 11 || a == 16)
                {
                    for (int i = 0; i < 15; i++)
                        Console.Write("_");

                }
                else if (a < 16)
                {
                    for (int i = 0; i < 15; i++)
                    {
                        if (a == 7||a==10)
                        {
                            if (i == 8)
                            {
                                Console.Write("*");
                                i = i + 1;
                            }
                        }
                        if (a == 8 || a == 9)
                        {
                            if (i == 7 || i == 9)
                            {
                                Console.Write("*");
                                i = i + 1;
                            }
                        }
                       
                        Console.Write(" ");
                    }
                }
                if(a<17)
                Console.Write("|");
                Console.WriteLine();
            }
            for (int i = 1; i < 4; i++)
            {
                a=25;
                for (int k = 0; k < (a - (i * 5)); k++)
                    Console.Write(" ");
                for (int j = 0; j < (i * 10); j++)
                    Console.Write("_");
                Console.WriteLine();
                for (int k = 0; k < (a - (i * 5)-1); k++)
                    Console.Write(" ");
                Console.Write("|");
                for (int j = 0; j < (i * 10); j++)
                    Console.Write(" ");
                Console.Write("|");
                Console.WriteLine();
            }


                Console.ReadLine();
        }
    }
}