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.
TIA
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.
TIA
Hey @Joseph! How about something like this?
<script>
// Function to check if a string contains a link
function containsLink(text) {
const linkRegex =
/((https?:\/\/)?(www\.)?[a-zA-Z0-9-]+\.[a-zA-Z0-9]+(\/\S*)?)|www\.[a-zA-Z0-9-]+\.[a-zA-Z0-9]+(\/\S*)?/i;
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);
});
</script>