PROGRAMMING

Simple spam protection for email addresses using jQuery

#javascript , #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(/[^[email protected]]+/g,'');
    $(this).replaceWith(value);
});

Example html code.

<span class="wtf" id="e[*]s//h--l||[email protected]$!$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.