Friday, July 15, 2011

Client side validation Using Javascript

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>Untitled Pagetitle>

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

function valid()

{

if(document.getElementById('TextBox1').value=="")

{

alert("blank");

document.getElementById('TextBox1').focus();

return false;

}

if(document.getElementById('TextBox1').value.length<3)

{

alert("short length");

document.getElementById('TextBox1').focus();

return false;

}

if(document.getElementById('TextBox2').value=="")

{

alert("again blank");

document.getElementById('TextBox2').focus();

return false;

}

if(document.getElementById('TextBox3').value=="")

{

alert("this field can not be blank")

document.getElementById('TextBox3').focus();

return false;

}

// if(document.getElementById('TextBox3').value!=document.getElementById('TextBox2').value)

// {

// alert("both field are not same")

// document.getElementById('TextBox3').focus();

// return false;

// }

var add=/^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;

var eadd=document.getElementById('TextBox3').value;

var myarray=eadd.match(add);

if(myarray==null)

{

alert("not in correct format");

document.getElementById('TextBox3').focus();

return false;

}

return true

}

script>

head>

<body>

<form id="form1" runat="server">

<div>

<br />

<asp:TextBox ID="TextBox1" runat="server">asp:TextBox>

<br />

<br />

<asp:TextBox ID="TextBox2" runat="server">asp:TextBox>

<br />

<br />

<asp:TextBox ID="TextBox3" runat="server">asp:TextBox>

<br />

<br />

<br />

<asp:Button ID="Button1" runat="server" Text="Button"

OnClientClick="return valid()" onclick="Button1_Click1" />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

div>

form>

body>

html>

code of armestrong no,,,febo series,,,palindrome

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

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
//int i, j;
//for (i = 0; i < 4; i++)
//{
// for (j = 4; j > i; j--)
// {
// System.Console.Write("*");

// }
// System.Console.WriteLine();
//}
//System.Console.ReadLine();






////////// for checking palindrome no......
//System.Console.WriteLine("Please enter any no to check wheather it is palindrome or not?");
//int i, j, k, l;
//l = 0;
//string s = System.Console.ReadLine();
//i = Convert.ToInt16(s);
//j = i;
//while (i != 0)
//{
// k = i % 10;
// l = l * 10 + k;
// i = i / 10;
//}
//if (j == l)
//{
// System.Console.WriteLine("Its is palindrome no");
//}
//else
//{
// System.Console.WriteLine("it is not palindrome");
//}
//System.Console.ReadLine();


///////////for armestrong no;;;;




//System.Console.WriteLine("Please enter any no to check wheather it is armestrong or not?");
//int i, j, k, l;
//l = 0;
//string s = System.Console.ReadLine();
//i = Convert.ToInt16(s);
//j = i;
//while (i != 0)
//{
// k = i % 10;
// l = (l + k * k * k);

// i = i / 10;

//}
//if (j == l)
//{
// System.Console.WriteLine("Its is armestrong no");
//}
//else
//{
// System.Console.WriteLine("it is not armestrong");
//}
//System.Console.ReadLine();


int i, j;
int fib=1;
i = -1;
j = 1;
int n = 50;
while (fib <= n)
{
fib = i + j;
i = j;
j = fib;
System.Console.WriteLine(fib.ToString());
}
System.Console.ReadLine();

}

}
}