logo

NJP

Disallow emojis in this conversation

Import · Feb 04, 2022 · article

Disallow emojis in this conversation

VA includes a feature called Text input format. This helps ensure that users enter information in the correct format. For example, an email address field might require an "@" symbol and a period (".") to be considered valid. If someone enters something that doesn't meet these requirements, the form will display a message explaining the issue. This helps users avoid submitting incorrect data and prevents frustration down the line.

image

Choosing "Text" as the format permits emojis, but there's no built-in way to exclude them. Fortunately, a simple regular expression can effectively remove emojis from the text. Select the custom option and write the logic to reject code.

Option to promt user to enter text again.

function validate(value) {

    var inputText = value; // user input value

    var emojiRegex = /([\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g; // regex using unicode to reject emojis

    var filteredText = inputText.match(emojiRegex, ""); // check if user input has emoji

    var isValid = filteredText === null; // if filteredtext is null then no emoji

    return {
            valid: isValid,
            error: isValid ? undefined : "Sorry, emoji's are not allowed"
    };

}

image

To remove emoji from user's input without promting - instead of inputText.match(regex, "") use inputText.replace(regex, "")

image

Thanks,

Murali

View original source

https://www.servicenow.com/community/virtual-agent-nlu-articles/disallow-emojis-in-this-conversation/ta-p/2306030