Skip to content

Instantly share code, notes, and snippets.

@gidili
Created January 31, 2013 16:46
Show Gist options
  • Save gidili/4684261 to your computer and use it in GitHub Desktop.
Save gidili/4684261 to your computer and use it in GitHub Desktop.
simple javascript profanity check
// extend strings with the method "contains"
String.prototype.contains = function(str) { return this.indexOf(str) != -1; };
// profanities of choice
var profanities = new Array("ass", "cunt", "pope");
var containsProfanity = function(text){
var returnVal = false;
for (var i = 0; i < profanities.length; i++) {
if(text.toLowerCase().contains(profanities[i].toLowerCase())){
returnVal = true;
break;
}
}
return returnVal;
}
var myText = $('#text').html();
if(containsProfanity(myText)){
$('#result').html('That language is profane dude.');
}
else{
$('#result').html('That language is just fine.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment