Javascript Example
Screen shot
Javascript code for form validation with alert

<html>
<head>
<title>Javascript Form Validation with Alert</title>
<script language="javascript">
function validate()
{
msg = "Please fill the following information:\n\n";
str = "";

if(document.frm.userid.value=='')
{
str+="-Please Insert User ID\n";
}

if(document.frm.password.value=='')
{
str+="-Please Insert Password\n";
}

if(document.frm.password.value!=document.frm.confirm_password.value)
{
str+="-Password and Confirm Password does not Match\n";
}

var validate_char= /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
if(!document.frm.email.value.match(validate_char))
{
str+='-Please enter a valid email address\n';
}

if(str)
{
alert(msg+str);
return false;
}
else
{
return true;
}

}
</script>
</head>
<body>
<form name="frm" action="" method="post" onSubmit="return validate()">
<table border="1" align="center">
<tr>
<td>User ID</td>
<td><input name="userid" type="text"></td>
</tr>
<tr>
<td>Password</td>
<td><input name="password" type="password"></td>
</tr>
<tr>
<td>Confirm Password</td>
<td><input name="confirm_password" type="password"></td>
</tr>
<tr>
<td>Email</td>
<td><input name="email" type="text"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input name="btnsubmit" type="submit" value="Submit">
</td>
</tr>
</table>
</form>
</body>
</html>

You can download source code here