JavaScript Form Validation

<script type=”text/javascript”>
function validate() {

var name = document.getElementById(‘name’)
var email = document.getElementById(’email’)
var mob = document.getElementById(‘mob’)
var detail = document.getElementById(‘detail’)
var Cname = document.getElementById(‘Cname’)

if (name.value == “”) {

alert(“Please Enter Name”)

name.focus()

return false;
}
if (email.value == “”) {
alert(“Please Enter email”)
email.focus()
return false;
}

var x = document.getElementById(’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”);
email.focus()
return false;

}
if (mob.value == “”) {
alert(“Please Enter mobile”)
mob.focus()
return false;
}
if (detail.value == “”) {
alert(“Please Enter Details”)
detail.focus()
return false;
}
if (Cname.value == “”) {
alert(“Please Enter Quantity”)
Qty.focus()
return false;
}

}
</script>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s