August 22, 2012

November 25, 2019

Simple spam protection for email addresses using jQuery

I wrote this short code for my blog. Go to the contact section to see how it works.

$("span.wtf").click(function() {
var value = $(this)
.attr("id")
.replace(/[^a-zA-Z0-9@.]+/g, "")
$(this).replaceWith(value)
})

Example html code.

<span class="wtf" id="e[*]s//h--l||o--x@g$!$m!!a()i***l.?c%*%o!#m">
Click here to show e-mail address
</span>

Simple solution. When you click "Click here to show e-mail address", script removes all characters from id, except letters, numbers, @ and commas. Next, replacing the text with e-mail address.

© 2020 Przemysław Kołodziejczyk