WE'RE HERE TO HELP!

Sample Javascript for Web Form Field Validation

Below is a sample javascript for Web Form Field Validation

<script type=”text/javascript”>

function validateForm() {
if (validateFormElements() == true) {
return lm_SubmitWebForm();
} else {
return false;
}
}
function validateFormElements() {
// check radio button fields for FIELDNAME are not blank
if (( frm.FIELDNAME[0].checked == false ) && ( frm.FIELDNAME[1].checked == false ))
{
alert(“Please select a location.”);
return false;
}
if (document.frm.first_name.value == ”) {
alert(“Please enter your first name.”);
document.frm.first_name.focus();
return false;
}
if (document.frm.last_name.value == ”) {
alert(“Please enter your last name.”);
document.frm.last_name.focus();
return false;
}
if (document.frm.Company.value == ”) {
alert(“Please enter your company name.”);
document.frm.Company.focus();
return false;
}
if (document.frm.Title.value == ”) {
alert(“Please enter your title.”);
document.frm.Title.focus();
return false;
}
if (document.frm.Phone.value == ”) {
alert(“Please enter your phone number.”);
document.frm.Phone.focus();
return false;
}
if (document.frm.Email.value == ”) {
alert(“Please enter your email address.”);
document.frm.Email.focus();
return false;
}
// check email address format
var rx = /^[\w\.-]+@[\w\.-]+\.\w+$/i;
if (!rx.test(document.frm.Email.value)) {
alert(“The format of your email address is incorrect. Please re-enter.”);
document.frm.Email.focus();
return false;
}
return true;
}
</script>
<!– checkbox validation code –>

// check Agree Checkbox is not blank
if (frm.FIELDNAME.checked == false)
{
alert(“You need to put a checkmark in the box.”);
return false;
}

Was this article helpful?
How can we improve this article?

Leave a Reply

Your email address will not be published. Required fields are marked *

Share This

Share on facebook
Share on twitter
Share on linkedin
Share on skype
Share on email
Share on print

Need More Help?

Can't find what you're looking for?
Email Us

WHAT'S NEW IN APP4

In This Article
Scroll to Top