/ Published in: JavaScript

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<script type="text/javascript"> function validateForm (submit) { var errmsg = "Oops, you're required to complete the following fields! \n"; if (submit.email.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1) { errmsg = errmsg + " - Valid email\n"; } //Validate other form fields, etc, etc. if (submit.name.value=="") { errmsg = errmsg + " - Full Name\n"; } //alert if fields are empty and cancel form submit if (errmsg == "Oops, you're required to complete the following fields! \n") { sub.submit(); } else { alert(errmsg); return false; }
Comments
