Simple spam protection for email addresses using jQuery

August 22, 2012 - IT

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

$('').click(function() {
    var value = $(this).attr('id').replace(/[^[email protected]]+/g,'');

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

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.