
Hiee..
actually i have developed a sign up page where the details get stored in to database after registration. So i want to validate the user details during the signing up process whether the user name is already registered or not... if the user name exist in the data base i should get an alert that user name is already regstrd please choose new username... pls help me...
MY CODE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script>
function validateForm()
{
//var x=document.forms["myform"]["funame"].value;
var x=document.getElementById("funame").value;
if (x==null || x=="")
{
alert("First name must be filled out");
return false;
}
var a=document.getElementById("luname").value;
if (a==null || a=="")
{
alert("Last name must be filled out");
return false;
}
var y=document.getElementById("password").value;
var z=document.getElementById("cpassword").value;
if(y!=z)
{
alert("Idiot password and confirm password doesnot match");
return false;
}
}
</script>
</head>
<body bgcolor=#1F3D4C>
<form name="myform" action="urlpat" method="post" onsubmit="return validateForm()">
<div id="container" style="width:500px">
<div id="header" style="background-color:#66293D;">
<h1 style="margin-bottom:0;width=1500;">SPARK REGISTARTIONS</h1></div>
<table align="center">
<th><h1>SIGN UP<h1></th>
<tr><td>enter first name:</td><td><input type="text" name="funame" id="funame"></td></tr>
<tr><td>enter last name:</td><td><input type="text" name="luname" id="luname"></td></tr>
<tr><td>enter user name:</td><td><input type="text" name="username"></td></tr>
<tr><td>choose password:</td><td><input type="password" name="password" id="password"></td></tr>
<tr><td>confirm password:</td><td><input type="password" name="cpassword" id="cpassword"></td></tr>
<tr><td>enter fathers name:</td><td><input type=text name="fathername"></td></tr>
<tr><td>enter ur emailid</td><td><input type="text" name="emailid"></td></tr>
</table><center>
<h4>Gender</h4>
Male<input type="radio" name="gender" value="male">
Female <input type="radio" name="gender" value="female"><br>
<h4>select your country</h4>
<select name="country">
<option value="india">INDIA</option>
<option value="australia">AUSTRALIA</option>
<option value="usa">USA</option>
<option value="srilanka">SRILANKA</option>
<option value="france">FRANCE</option>
<option value="china">CHINA</option><br>
</select>
<table align="center">
<th><h4>select your programming skills</h4></th>
<tr><td><input type="checkbox" name="programming concepts" value="java">java</td></tr>
<tr><td><input type="checkbox" name="programming concepts" value="c">c</td></tr>
<tr><td><input type="checkbox" name="programming concepts" value="c++">c++</td></tr>
<tr><td><input type="checkbox" name="programming concepts" value=".net">MS.NET</td></tr>
</table>
<input type="submit" value="submit"></br>
<h4>If Registered User please Sign In</h4>
<a href="signin.html" "background-color:#002233;">SIGN IN</a>
</div>
</form></center>
</body>
</html>

Here is a code that validates fields of html form using javascript.
<html>
<h2>Form Validation</h2>
<script language = "Javascript">
function checkEmail() {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.email.value)){
return true;
}
return false;
}
function checkName(str){
var re = /[^a-zA-Z]/g
if (re.test(str)) return false;
return true;
}
function checkAddress(str){
var re = /[^[a-z][A-Z][0-9]]/g
if(re.test(str)) return false;
return true;
}
function validate(){
var emailID=document.form.email;
var nn=document.form.name;
var add=document.form.address;
if((nn.value==null)||(nn.value=="")){
alert("Please Enter your Name!")
nn.focus();
return false
}
if(checkName(nn.value)==false){
nn.value=""
alert("Invalid Name!");
nn.focus()
return false
}
if((emailID.value==null)||(emailID.value=="")){
alert("Please Enter your Email ID!")
emailID.focus()
return false
}
if (checkEmail(emailID.value)==false){
emailID.value=""
alert("Invalid Email Adderess!");
emailID.focus()
return false
}
if ((add.value==null)||(add.value=="")){
alert("Please Enter your Address!")
add.focus()
return false
}
if (checkAddress(add.value)==false){
add.value=""
alert("Invalid Adderess!");
add.focus()
return false
}
if(document.form.qua.selectedIndex==""){
alert ( "Please select your qualification!" );
return false;
}
return true
}
</script>
<form name="form" method="post" onSubmit="return validate()">
<pre>
Enter Name: <input type="text" name="name" size="30"><br>
Enter an Email Address : <input type="text" name="email" size="30"><br>
Enter Address <textarea name="address" rows="5" cols="23"></textarea><br>
Select Qualification: <select name="qua">
<option value="BTech">BTech</option>
<option value="MBBS">MBBS</option>
<option value="MBA">MBA</option>
<option value="MCA">MCA</option>
</select><br>
<input type="submit" name="Submit" value="Submit">
</pre>
</form>
</html>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.