Monday, April 28, 2008

How To Validate Email Id Using JavaScript

<html>
<head>
<script>
String.prototype.ValidateEmail = function (evt)
{
var eVal = new RegExp("\\w+([-+.\’]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
var chkVal = eVal.exec(this);
if(chkVal != null)
{
alert('Id Correct');
}
else
{
alert('Check Your Id');
}
</script>
</head>
<body>
<input type="text" id="txtEmail" width="30px" onblur="this.value.ValidateEmail();" />
</body>
</html>
ProgramDemo

Tuesday, April 15, 2008

How To Add Edit Delete Item In ListBox

This program used to add,edit and remove the item in the listbox control, this code can be used for both the serverside control and also for clientside control.

JavaScript Part:
Add Item To ListBox:

             function addItem()
{
var lst = document.getElementById('lstbox'); // listbox control id
var newItem = prompt("Enter New Item","Enter Value Here");
                      //Option object is created for every option in a selection
//new Option([text[, value[, defaultSelected[, selected]]]]) // Syntax
                      if(newItem == null)
{
return false;
}
else
{
lst.options[lst.length] = new Option(newItem,newItem,false,false);
return false;
}
}
Edit Item To ListBox:
             function editItem()
{
var lst = document.getElementById('lstbox'); // listbox control id
var selVal = lst.value;
if(selVal != "")
{
var newItem = prompt("Enter New Item",selVal);
if(newItem == null)
{
return false;
}
else
{
lst.options[lst.selectedIndex] = new Option(newItem,newItem,false,false);
return false;
}
}
else
{
alert('Select Item From The List To Edit ');
}
}
Remove Item For The Listbox

function rmItem()
{
var lst = document.getElementById('lstbox');// listbox control id
var selVal = lst.value;
if(selVal != "")
{
var msg = confirm("Do You Want To Remove ( "+selVal+" ) From The List");
if(msg == true)
{
lst.options[lst.selectedIndex] = null;
}
}
else
{
alert('Select Item To Remove From The List');
}
return false;
}




HTML Part

<div>

<select id="lstbox" multiple=multiple style="width:100px; overflow:auto;">

</select>

<input type="button" id="btnAdd" value="Add" onclick="return addItem();" />

<input type="button" id="btnEdit" value="Edit" onclick="return editItem();" />

<input type="button" id="btnDel" value="Delete" onclick="return rmItem();" />

</div>

Programe Demo

Sunday, April 13, 2008

How To Sort Numbers Using JavaScript

<html>
     <head>
           <title>
                Sorting Number Using JavaScript
           </title>
                 <script type="text/JavaScript" language="JavaScript">

                   
 Array.prototype.SrtNum = function()
                   {
                          return this.sort( function (a,b) { return a-b; } );
                   }


                   var arr = [5,9,1,10,8,4,2,7,3];
                   document.write("Before Sorting :"+arr+"<br />After                    Sorting :"+arr.SrtNum());
                   alert(arr=arr.SrtNum());

                     </script>
               
<head>
          <body>
     </body>
</html>

Program Demo

Wednesday, April 9, 2008

How To Create User Defined Tag In WebConfig

WebConfig
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="YourTagName" type="System.Configuration.NameValueFileSectionHandler,System, Version=1.0.3300.0, Culture=neutral,PublicKeyToken=b77a5c561934e089"/>
.
.
.
.
</configSections>
<appSettings>
.
.
.
</appSettings>
<YourTagName>
<add key="YourKeyName1" value="Xploredotnet"/>
<add key="YourKeyName2" value="adminpwd"/>
</YourTagName>

.
.
.
.
.
</configuration>



Code Behind
This is one of the way to access Custom Tag

string AdUrs,AdPwd;
AdUrs = ((System.Collections.Specialized.NameValueCollection)ConfigurationManager.GetSection("YourTagName"))["YourKeyName1"] +string.Empty;
AdPwd = ((System.Collections.Specialized.NameValueCollection)ConfigurationManager.GetSection("YourTagName"))["YourKeyName2"] + string.Empty;

Monday, April 7, 2008

Attributes Of Highly Effective Programmers - Quality Of A Developer - Self-criticism

Today I had come across two articles and I feel that its good and all the programmers should read this articles.I like to share this for my blog readers.I'm posting the abstract here, so through the orginal articles.

Top 5 Attributes of Highly Effective Programmers

  • Humility
  • Love of Learning
  • Detail-orientedness
  • Adaptability
  • Passion

The most important quality of a developer: Self-criticism

"Don't just implement the first design you come out with, but try and refine looking at it from different angles before to start writing code.

Don't just release the first piece of code you come out with, but do a self review and try to make it clearer and better.

The best developers/architects are the ones that always criticized their own work in order to make it better."