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.

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

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

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