
Hi deepak,
sample example on javascript form validation

<html>
<script>
function checkName(text) {
if(isNaN(text)){
return 1;
}
else{
alert("Please enter a valid name. The only charachters accepted are A - Z and a - z");
return 0;
}
}
function checkAddress(text) {
if(isNaN(text)){
return 1;
}
else{alert("Please enter a valid address. The only charachters accepted are A - Z and a - z");return 0;}
}
function validate(){
if(document.form.name.value == ""){
alert( "Please enter name." );
document.form.name.focus();
return false;
}
if(checkName(document.form.name.value)==false){
document.form.name.focus();
document.form.name.value == ""
return false
}
if(document.form.address.value == ""){
alert("Please enter address.");
document.form.address.focus();
return false;
}
if(checkAddress(document.form.address.value)==false){
document.form.address.focus();
document.form.address.value == ""
return false
}
if(document.form.contactNo.value == ""){
alert("Please enter contact No." );
document.form.contactNo.focus();
return false;
}
var con=document.form.contactNo.value;
var ex = new RegExp(/^\d+$/);
var t=ex.test(con);
if(!t){
alert("Enter only Number .");
document.form.contactNo.focus();
return false;
}
}
</script>
<form name="form" method="post" onsubmit="return validate();">
<table>
<tr><td>Enter Name</td><td><input type="text" name="name"></td></tr>
<tr><td>Enter Address</td><td><input type="text" name="address"></td></tr>
<tr><td>Enter Contact No</td><td><input type="text" name="contactNo"></td></tr>
<tr><td></td><td><input type="submit" value="Add" name="button"></td></tr>
</table>
</form>
</html>

<html>
<script >
function validate(){
if(document.form.name.value == ""){
alert( "Please enter name." );
document.form.name.focus();
return false;
}
if (document.form.address.value == ""){
alert ( "Please enter address." );
document.form.address.focus();
return false;
}
if(( document.form.radio[0].checked == false ) && ( document.form.radio[1].checked == false ) ){
alert ( "Please choose Gender: M or F" );
document.form.radio[0].focus();
return false;
}
if( document.form.qua.selectedIndex == 0 ){
alert ( "Please select Qualification." );
document.form.qua.focus();
return false;
}
if(!multiselect(document.getElementById('specialization'))){
alert ( "Please select Specialization." );
return false;
}
if ((document.form.lang1.checked == false) &&(document.form.lang2.checked == false) &&(document.form.lang3.checked == false)&&(document.form.lang4.checked == false))
{
alert ('You didn\'t choose any of the checkboxes!');
return false;
}
var oRadio = document.forms[0].elements[radio].value;
document.write(oRadio);
return true;
}
function multiselect(select) {
var valid = false;
for(var i = 0; i < select.length; i++) {
if(select.options[i].selected) {
valid = true;
break;
}
}
return valid;
}
</script>
<form name="form" method="post" onsubmit="return validate();">
<table>
<tr><td>Enter Name</td><td><input type="text" name="name"></td></tr>
<tr><td>Enter Address</td><td><textarea rows="4" cols="8" name="address"></textarea></td></tr>
<tr><td>Gender</td><td><input type="radio" name="radio">M<input type="radio" name="radio">F</td></tr>
<tr><td>Qualification</td><td><select name="qua"><option value="BTech">BTech</option><option value="BTech">MBA</option><option value="BTech">MCA</option><option value="BTech">MTech</option></select></td></tr>
<tr><td>Specialization</td><td><select id="specialization" name="specialization" multiple="multiple" ><option value="Software">Software</option><option value="Hardware">Hardware</option><option value="Electrical">Electrical</option><option value="Mechanical">Mechanical</option><option value="Finance">Finance</option><option value="Finance">Marketing</option></select></td></tr>
<tr><td>Languages</td><td><input type="checkbox" name="lang1" value="Hindi">Hindi<input type="checkbox" name="lang2" value="English">English<input type="checkbox" name="lang3" value="French">French<input type="checkbox" name="lang4" value="German">German</td></tr>
<tr><td><input type="submit" value="Submit" ></td><td><input type="reset"></td></tr>
</table>
</form>
</html>

<html>
<head>
<title>toString() method </title>
<script language="JavaScript">
function convertToString()
{
alert(new Date().toString());
}
</script>
</head>
<body>
<div style="background: #ff9900; width:'100%';"
align="center">
<font color="#0000ff" size="12pt">
<b>toString() Example</b>
</font>
</div>
<center>
<p>
Click on the following button to show date
into string
</p>
<input type="button" value="Convert current date to
String" onClick="return convertToString();"/>
</center>
</body>
</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.