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
|
No comments:
Post a Comment
Note: only a member of this blog may post a comment.