Tuesday, December 29, 2015

Find and replace control characters in a string

function findControlChars (vInput)
{
    var pattern = /[\u0000-\u001F]/g;
    var matches = vInput.match(pattern);
    if (matches)
    {
        return true;
    }
    
    return false;
}

function replaceControlChars (vInput, vReplaceChar)
{
    var replaceChar = "";
    if (!(typeof vReplaceChar === "undefined"))
    {
        replaceChar = vReplaceChar;
    }

    var wrkfield = vInput.replace(/[\u0000-\u001F]/g, replaceChar);
   
    return wrkfield;
}

No comments:

Post a Comment