I have very little javascript knowledge so would appreaciate some help onthis please.
I have the following code on my form test.
if (formx.description.value == "") {
alert("Please enter a description of what you are contacting David Brown about.");
formx.description.focus()
return false;
}
But I also want to be able to test to see if the message field contains the following
<a href=
</a>
If it does I would like an error message that comes up saying you can’t include links. Is this possible?
Hi Struggling,
Try something like…
dirtyValue = document.formx.description.value;
cleanValue = dirtyValue.replace(/<a\\b[^>]*>(.*?)<\\/a>/i,"");
… this will remove <a>'s from the designated value.
Will this stop the form being submitted?
This strip_tags code might be very useful for you:
JavaScript strip_tags
That way you can automatically remove all tags from the form value:
formx.description.value = striptags(formx.description.value);
Or you can choose to remove only certain tags that you care about, such as links and scripts:
formx.description.value = striptags(formx.description.value, '<a><script>');