Skip to content

Instantly share code, notes, and snippets.

@netsi1964
Last active October 10, 2015 19:07
Show Gist options
  • Save netsi1964/3737118 to your computer and use it in GitHub Desktop.
Save netsi1964/3737118 to your computer and use it in GitHub Desktop.
Simpel antiSpam javascript
function antiSpam(sIDOfFormToWatch, preInfo, postInfo) {
preInfo = (preInfo || 'This page is being spammed.\nPlease confirm that you are human by entering: "');
postInfo = (postInfo || '"');
var s = document.getElementById(sIDOfFormToWatch);
if (s === null) return;
var oldSubmit = s.onsubmit;
if (s === null) oldSubmit = function() {
return true;
};
s.onsubmit = function(t) {
var r = parseInt(Math.random() * 1000);
if (prompt(preInfo + r + postInfo, '') != r) {
return false;
} else {
oldForm.call(this, t);
}
return false;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment