Validation In JavaScript

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>



function validateForm()
var x=document.forms["myForm"]["fname"].value;
if (x==null || x=="")
  alert("First name must be filled out");
  return false;

var x=document.forms["myForm"]["email"].value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
  alert("Not a valid e-mail address");
  return false;

var x=document.forms["myForm"]["message"].value;

if (x==null || x=="" || x.length<10)
  alert("First message must be filled out and no tless than 10");
  return false;




<fieldset style="width:200px; background-color:#CCC;" id="field">
<legend>Conatct Me</legend>
<form name="myForm" action="thanks.php" onsubmit="return validateForm()" method="post">
<label>First name:</label> <input type="text" name="fname"><br />
<label>Email:</label> <input type="text" name="email"><br />
<label>Message : </label> <textarea name="message" >

</textarea><br />
<input type="submit" value="Submit">


Leave a Reply