Subscribe
TechTasks.net

The Blog is Moved to www.TechTasks.net



Thanks for Visiting www.funnydotnet.co.cc

Design

In Coding Page Add Following code in Head Tag

<script type="text/javascript" >

function Validation()

{

//name

document.getElementById ('txtname');

if(name.value=='')

{

alert("Name Can't Blank");

getElementById ('txtname').focus();

return false;

}

//checking for only alphabets and name should be more than 4 char

var reforname=/^[A-Za-z]{4,50}$/;

var phone=document.getElementById('txtname').value;

if(phone.search(reforname))

//if(isNaN(phone))

{

alert("Enter Correct name");

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

return false;

}


//accepts only 10 digits

var reforphone=/^\d{10}$/;

var phone=document.getElementById('txtphone').value;

if(phone.search(reforphone))

{

alert("Enter Correct Phone No");

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

return false;

}

//Email Validation

var reforemail=/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;

var phone=document.getElementById('txtemail').value;

if(phone.search(reforemail))

{

alert("Enter Correct email");

document.getElementById('txtemail').focus;

return false;

}

//Dropdown list Validation

var dob=document.getElementById('ddldob');

if(dob.value=="select")

{

alert("select DOB");

return false;

}

//Radio Button Validation Here 'gender' is Group Name Of Radio Button

//if(document.getElementById('rb1').checked==false && document.getElementById ('rb2').checked==false)

if(document.form1.gender[0].checked==false && document.form1.gender[1].checked==false)

{

alert("select Gender");

return false;

}

//checkbox validation

if(document.getElementById('cb1').checked==false&& document.getElementById ('cb2').checked==false)

{

alert("select Alert Modes");

return false;

}

return true;

}



Add the Following Code In Page Load


//When Validation Function return True Then OnClick() is Fired (internally calls javaScript Function)

submit.Attributes.Add("OnClick","return Validation()");



Bookmark and Share
JavaScript Validatoin For Basic Controles in ASP.NET SocialTwist Tell-a-Friend

0 comments:

Subscribe to: Post Comments (Atom)
Thanks For Visiting