Regular Expressions JavaScript Tutorial

< html>

Bad Words Example

        function filterText(sText) {
            var reBadWords = /badword|anotherbadword/gi;
            return sText.replace(reBadWords, function (sMatch) {
                return sMatch.replace(/./g, "*");
            });
        }
        function showText() {
            var oInput1 = document.getElementById("txt1");
            var oInput2 = document.getElementById("txt2");
            oInput2.value = filterText(oInput1.value);
        }



    badword anotherbadword
    


    

Filtered Text: