javascript - How to remove flooding from text via js? -
i don't know name of want, i'll show you.
i have input text users can ask questions, there users asking questions these: what the?????????????????????%%%%%% or question?????????????????????? .... or !!!!!!?????? .... etc.
i remove these strings javascript variable. function me? , english name i'm looking for?
thank you.
example in javascript, regexp similar in other languages:
var compressspecialchars = function(str) { return str.replace(/[^\w\d\s]+/g, function(specials) { return specials[0] }); }; var questions = [ 'what the?????????????????????%%%%%%', 'question??????????????????????', '!!!!!!??????' ]; questions.map(compressspecialchars); // result: ["what the?", "question?", "!"]
Comments
Post a Comment