Created
January 31, 2013 16:46
-
-
Save gidili/4684261 to your computer and use it in GitHub Desktop.
simple javascript profanity check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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