javascript
function checkfname(elem)
{
var alphaExp = /[^a-zA-Z]/;
if (elem.value.length == 0 || alphaExp.test(elem.value)) {
alert("Firstname should not be blank and only characters");
elem.focus();
return false;
}
return true;
}
function checklname(elem)
{
var alphaExp = /[^a-zA-Z]/;
if (elem.value.length == 0 || alphaExp.test(elem.value))
{
alert("Lastname should not be blank and only characters");
elem.focus();
return false;
}
return true;
}
function validatenum(elem)
{
if (isNaN(elem.value) || (elem.value.length!=10))
{
alert("Contact Number should be number and ten characters only");
return false;
elem.focus();
}
return true;
}
function validateadd(elem)
{
if (elem.value.length == 0)
{
alert("Address field Can't be left blank");
elem.focus();
return false;
}
return true;
}
function validateemail(elem)
{
var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
if (emailExp.test(elem.value))
{
return true;
}
else
{
alert("Not a valid Email Format");
elem.focus();
return false;
}
}
function checkuname(elem)
{
var alphaExp = /[^a-zA-Z]/;
if (elem.value.length == 0 || alphaExp.test(elem.value))
{
alert("Username should not be blank and only characters");
elem.focus();
return false;
}
return true;
}
function checkpass(elem)
{
if (isNaN(elem.value) || elem.value.length == 0)
{
alert("Enter only Numbers and can't be left blank");
return false;
}
return true;
}
function conpass(elem,elem1) {
if (elem1.value != elem.value || (isNaN(elem1.value)) || elem1.value.length ==0 )
{
alert("Password doesn't match");
return false;
}
return true;
}
function checkall()
{
var firstname = document.getElementById("fname");
var lastname = document.getElementById("lname");
var num = document.getElementById("number");
var add = document.getElementById("address");
var email = document.getElementById("email");
var uname = document.getElementById("uname");
var password = document.getElementById("pwd");
var cpassword = document.getElementById("cpwd");
if (checkfname(firstname)) {
if (checklname(lastname)) {
if (validatenum(num)) {
if (validateadd(add)) {
if (validateemail(email)) {
if (checkuname(uname)) {
if (checkpass(password)) {
if (conpass(password, cpassword)) {
return true;
}
}
}
}
}
}
}
}
return false;
}
file in the aspx page:
<table class="newusertable" align="center">
<tr>
<td class="tbox" valign="top">
First Name:</td>
<td class="style2">
<asp:textbox class="txtbkcolor" id="fname" runat="server" width="160px" xmlns:asp="#unknown"></asp:textbox>
</td>
</tr>
<tr>
<td class="tbox" valign="top">
Last Name:</td>
<td class="style2">
<asp:textbox class="txtbkcolor" id="lname" runat="server" width="171px" xmlns:asp="#unknown"></asp:textbox>
</td>
</tr>
<tr>
<td class="tbox" valign="top">
Gender:</td>
<td class="tbox">
<asp:radiobutton id="rbmale" class="tbox" runat="server" checked="True" groupname="a" xmlns:asp="#unknown">
Text="Male" />
<asp:radiobutton id="rbfemale" class="tbox" runat="server" groupname="a" text="Female" />
</asp:radiobutton></td>
</tr>
<tr>
<td class="tbox" valign="top">
Phone No.:</td>
<td class="tbox">
<asp:textbox class="txtbkcolor" id="number" runat="server" width="170px" xmlns:asp="#unknown"></asp:textbox>
</td>
</tr>
<tr>
<td class="tbox" valign="top">
Address:</td>
<td class="style1">
<asp:textbox class="txtbkcolor" id="address" runat="server" textmode="MultiLine" xmlns:asp="#unknown"></asp:textbox>
</td>
</tr>
<tr>
<td class="tbox">
Email ID</td>
<td class="style2">
<asp:textbox class="txtbkcolor" id="email" runat="server" width="184px" xmlns:asp="#unknown"></asp:textbox>
</td>
</tr>
<tr>
<td class="tbox" valign="top">
UserName:</td>
<td class="style2">
<asp:textbox class="txtbkcolor" id="uname" runat="server" width="179px" xmlns:asp="#unknown"></asp:textbox>
</td></tr>
<tr>
<td class="tbox" valign="top">
Password:</td>
<td class="style2">
<asp:textbox class="txtbkcolor" id="pwd" runat="server" width="179px" xmlns:asp="#unknown">
TextMode="Password"></asp:textbox>
</td></tr>
<tr>
<td class="tbox" valign="top">
Confirm Password:</td>
<td class="style2">
<asp:textbox class="txtbkcolor" id="cpwd" runat="server" width="179px" xmlns:asp="#unknown">
TextMode="Password"></asp:textbox>
</td></tr>
<tr>
<td class="tbox" valign="top">
Security Question:</td>
<td class="style2">
<asp:textbox class="txtbkcolor" id="secques" runat="server" width="179px" xmlns:asp="#unknown"></asp:textbox>
</td></tr>
<tr>
<td class="tbox" valign="top">
Answer:</td>
<td class="style2">
<asp:textbox class="txtbkcolor" id="secans" runat="server" width="179px" xmlns:asp="#unknown"></asp:textbox>
</td></tr>
<tr align="center">
<td colspan="2">
<asp:button class="but" id="submit" runat="server" text="Submit" onclientclick="return checkall();" xmlns:asp="#unknown">
onclick="submit_Click" Font-Bold="False"
Font-Size="Large"/>
<asp:button id="but_home" runat="server" class="but" font-bold="False">
Font-Size="Medium" onclick="but_home_Click"
Text="Login" Height="32px"
Width="65px" />
<asp:button class="but" id="cancel" runat="server" text="Cancel">
onclick="cancel_Click" Font-Bold="False" Font-Size="Medium" Height="31px"
Width="79px" />
</asp:button></asp:button></asp:button></td>
</tr>
</table>
For calling the javascript file in aspx page add the reference in head.
<head runat="server">
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<link href="CSS/createuser.css" rel="stylesheet" type="text/css" />
<script src="JS/NewUser.js" type="text/javascript"></script>
<style type="text/css">
.style1
{
width: 483px;
}
</style>
</head></head>