Escape special characters in a text

/**
 *escape special characters in a text
 * @param textvalue
 * @returns {*}
 */
function escapeSpecialChar1(textvalue) {

    try {
        textvalue = textvalue.replace(/&/g, '&');
        // textvalue = textvalue.replace(/</g, '&lt;');
        // textvalue = textvalue.replace(/>/g, '&gt;');
        textvalue = textvalue.replace(/"/g, '&quot;');
        textvalue = textvalue.replace(/'/g, '&apos;');
        return textvalue;
    } catch (e) {
        log.error({
            title: e.name,
            details: e
        });
    }


}

Leave a comment

Your email address will not be published. Required fields are marked *