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

User Registration Form Validation in JavaScript Source Code

Oct 4, 2013

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

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, 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="">
<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 != "") {
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 "";
<form id="form1" runat="server">
<table align="center">
<td><asp:TextBox ID="txtuser" runat="server" /></td>
<td>First Name</td>
<td><asp:TextBox ID="txtfname" runat="server" /></td>
<td><asp:TextBox ID="txtlocation" runat="server" /></td>
<asp:Button ID="btnsubmit" runat="server" Text="Save"
OnClientClick ="javascript:validate()" />
Live Demo

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

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

Get the latest,, 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


joe jagadeesh said...


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


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...


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 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.
Anonymous said...

Saranya P said...

Thank you for your validation code It is working Perfectly

Kamlesh Chaudhary said...

thank you for your validation code it use fully my project working......

Unknown said...

Aftr doing these Steps ..Add these button attributes...this help to avoid empty data save..
protected void Page_Load(object sender, EventArgs e)
Button1.Attributes.Add("onClick", "javascript:return check()");

Give your Valuable Comments

Other Related Posts

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