Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Introduction

Here I will explain how to validate user registration form in JavaScript with source code or JavaScript user registration form validation.
 
Description:

In previous article I explained how to set watermark text for textbox using JavaScript, Remove duplicate values from string array in JavaScript, Disable drag and drop options in textbox or textarea controls, JavaScript show number of characters left in textbox and many articles relating to asp.net, jQuery, JavaScript. Now I will explain how to implement registration form validation in JavaScript source code.

To implement this we need to write the code as shown below


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Registration Form Validation in JavaScript Source Code</title>
<script language="javascript" type="text/javascript">
function validate() {
var summary = "";
summary += isvaliduser();
summary += isvalidFirstname();
summary += isvalidLocation();
if (summary != "") {
alert(summary);
return false;
}
else {
return true;
}
}
function isvaliduser() {
var uid;
var temp = document.getElementById("<%=txtuser.ClientID %>");
uid = temp.value;
if (uid == "") {
return ("Please Enter UserName" + "\n");
}
else {
return "";
}
}
function isvalidFirstname() {
var uid;
var temp = document.getElementById("<%=txtfname.ClientID %>");
uid = temp.value;
if (uid == "") {
return ("Please enter firstname" + "\n");
}
else {
return "";
}
}
function isvalidLocation() {
var uid;
var temp = document.getElementById("<%=txtlocation.ClientID %>");
uid = temp.value;
if (uid == "") {
return ("Please enter Location" + "\n");
}
else {
return "";
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table align="center">
<tr>
<td>UserName</td>
<td><asp:TextBox ID="txtuser" runat="server" /></td>
</tr>
<tr>
<td>First Name</td>
<td><asp:TextBox ID="txtfname" runat="server" /></td>
</tr>
<tr>
<td>Location</td>
<td><asp:TextBox ID="txtlocation" runat="server" /></td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="btnsubmit" runat="server" Text="Save"
OnClientClick ="javascript:validate()" />
</td>
</tr>
</table>
</form>
</body>
</html>
Live Demo

To check for live demo try to click on below button
UserName
First Name
Location


If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

7 comments :

joe jagadeesh said...

hi,

could you post linq classes it will be useful to many.


Regards,
Jagadeesh

akshay Barve said...

Hi Suresh. You have posted a very good code but can u plz post a code where we can do validations on blur.
I mean in this example the code is done on button which is ok but what if i want to check the validations on blur effect of controls like checkboxlist, textbox , fileupload etc with some jquery animations. It would be really helpful if you do so.

Enos Sitholimela said...

Hi,

I have developed a system using VS ASP.Net 4.0 using C#, i have more than 45 web forms that i want to add validations text boxes with different id names.

So i want to apply the validations to more than 14 text boxes on a web form. how do you do it...I also want the following;

1.Validate for numbers only and change color of the text box to red.

2.Validate for Letters only only and change color of the text box to red.

Validate for invalid email address and change color of the text box to red.

4.Validate the range of date. e.g if he/she enters invalid date like 05/05/2001 ,i need the current date.

5.Highlight the text box to red for a required text box.

NagamalleswaraRao Mandava said...

Good for Beginners

Anjaneyulu said...

while am giving spaces it Allows...

sumit said...

sir i have added a event OnClick="btnpuja_Click" in button contron..it work fine but when in click on alert message(ok) it reload the page and emty data save in my db..plz help

D. arunkumar said...
This comment has been removed by a blog administrator.

Give your Valuable Comments

Other Related Posts

© 2010-2012 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.