# Form validation JS

**URL:** <https://forum.kirupa.com/t/form-validation-js/314955>\
**Category:** web dev\
**Created:** [October 13, 2010, 9:59am UTC](https://forum.kirupa.com/t/form-validation-js/314955 "2010-10-13T09:59:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave](https://avatars.discourse-cdn.com/v4/letter/d/ee7513/32.png) [@Dave](https://forum.kirupa.com/u/Dave)\
**Post date:** [October 13, 2010, 9:59am UTC](https://forum.kirupa.com/t/form-validation-js/314955/1 "2010-10-13T09:59:19Z")

</div>

Help! Trying to get this form to work.

This is the function I have to verify the form:

```auto

function verify() {
var themessage = "You are required to complete the following fields: ";
if (document.form.first.value=="") {
themessage = themessage + " - First Name";
}
if (document.form.last.value=="") {
themessage = themessage + " - Last Name";
}
if (document.form.email.value=="") {
themessage = themessage + " - E-mail";
}
//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields: ") {
document.form.submit();
}
else {
alert(themessage);
return false;
   }
}

```

So that is fine, but I also want to have the emai verified in a certain way checking for the ‘@’ and the ‘.com’.

I found a script but I can’t intergrate both of them, and when i run to function calls on the submit, only one works.

```auto

<script type="text/javascript">
function validate_email(field,alerttxt)
{
with (field)
  {
  apos=value.indexOf("@");
  dotpos=value.lastIndexOf(".");
  if (apos<1||dotpos-apos<2)
    {alert(alerttxt);return false;}
  else {return true;}
  }
}

function validate_form(thisform)
{
with (thisform)
  {
  if (validate_email(email,"Not a valid e-mail address!")==false)
    {email.focus();return false;}
  }
}
</script>

```

Can anyone help? Pulling my ahir out with this thing!!

Thank you!:red:
