Prevent links in message area of form

Looking for solution to inhibit submission of form if the message includes a link.

Goal is to reduce spammy type messages.

Tried a bunch from bard, copilot, and claud.

No joy so far.


Hey @Joseph! How about something like this?

  // Function to check if a string contains a link
  function containsLink(text) {
    const linkRegex =
    return linkRegex.test(text);

  // Function to validate the form before submission
  function validateForm(event) {
    const message = document.getElementById('message').value;
    if (containsLink(message)) {
      alert('Message contains a link. Please remove the link before submitting.');
      event.preventDefault(); // Prevent form submission

  // Attach the event listener to the form
  window.addEventListener('DOMContentLoaded', function () {
    const form = document.getElementById('myForm');
    form.addEventListener('submit', validateForm);