Prevent contact form to send urls

Asked by At

Hello

I’ve been using CF7 in ever website I’ve ever built/maintained. I’d not use anything else.

Just wondering if there is a way that we can stop spammers/bots from submitting forms that have URL’s in them? It’s the only spam I receive now and it always contains a URL. I’ve searched high and low for a solution before coming here so I’m really hoping there’s a simple code or function that can be added

I want to block submited message that contain urls in message content except my domain name (www and non-www) with php or jquery

1 Answers

0
Remco Bravenboer On

You could test the message against a regular expression, try the following JavaScript code.

let message = "";
if(new RegExp("([a-zA-Z0-9]+://)?([a-zA-Z0-9_]+:[a-zA-Z0-9_][email protected])?([a-zA-Z0-9.-]+\\.[A-Za-z]{2,4})(:[0-9]+)?(/.*)?").test(message)) {
    alert("url inside");
}

I am not really familiar with implementing this code in WordPress but this is how you can detect URL's in your message :)