C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Java Script validations for asp.net


Posted Date: 11 Sep 2008    Resource Type: Code Snippets    Category: Javascript

Posted By: Vivek Sharma       Member Level: Gold
Rating:     Points: 10



Java script for required field,numeric value only and regular expression
for e-mail check.The given code having the validation controls for a page
use this function in html on top and then call on page load with button reference on which it will work.



<script language ="javascript" type ="text/javascript" >
function validate()


var b = /^([0-9]*)$/;
var c= document.getElementById('<%=txtPhoneNo.ClientID %>').value;
if(document.getElementById('<%=txtFirstName.ClientID %>').value =="")
{
alert('Enter the firstname');
document.getElementById('<%=txtFirstName.ClientID %>').focus();
return false;
}
else if (!b.test(c))
{
alert(' Enter only numeric value in phone number');
document.getElementById('<%=txtPhoneNo.ClientID %>').focus();
document.getElementById('<%=txtPhoneNo.ClientID %>').select();
return false;
}
else if(document.getElementById('<%=txtEmail.ClientID %>').value !="")
{
validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
strEmail = document.getElementById('<%=txtEmail.ClientID %>').value;
if (strEmail.search(validRegExp) == -1)
{

alert(" A valid e-mail address is required");
document.getElementById('<%=txtEmail.ClientID %>').focus();
document.getElementById('<%=txtEmail.ClientID %>').select();
return false;
}
}
return true;
}

</script>

//Write this Code on page load//

ibtnRegister.Attributes.Add("onClick", "return validate();");

Regards
Vivek Sharma




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Java script validations for asp.net  .  Java script validations for .net  .  Java script validations  .  Client side validations  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Heading of the webpage - Type Writer Message
Previous Resource: Javascript code to allow only numeric keys
Return to Discussion Resource Index
Post New Resource
Category: Javascript


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

email fax service

Contact Us    Privacy Policy    Terms Of Use