
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
02-04-2022 12:13 AM - edited 06-25-2024 04:41 AM
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.
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"
};
}
To remove emoji from user's input without promting - instead of inputText.match(regex, "") use inputText.replace(regex, "")
Thanks,
Murali
- 1,116 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content