Skip to content

[Feature Request] Emoji validator #2902

Open

Description

@osm-dev-io

I'd like to contribute emoji validation to validator.js. Before starting implementation, I'd like to clarify the intended API and the definition of an emoji.

Previous discussions

I found several related issues and PRs

Between 2021-2022, there were lots of discussions and PRs about adding an isEmoji function to this project, but it seems that they are abandoned. So, I'd like to suggest closing them and starting fresh with this issue.

In those issues and PRs, two main questions came up.

  1. Name and behavior of the emoji validator.
    1. If the name is isEmoji, should it only determine if single character is emoji or not?
    2. If the name is hasEmoji or containsEmoji, should it determine if the given string contains an emoji in it or not?
  2. Which Unicode characters and sequences should count as emojis?

Suggestion

I'd like to implement two validators.

isEmoji

This validator checks whether the given string is exactly one complete emoji.

Example

validator.isEmoji("❤️"); // true
validator.isEmoji("🟢😆"); // false (two emojis)
validator.isEmoji("$"); // false (not emoji)

hasEmoji

This validator checks whether the given string contains at least one emoji in it.

Example

validator.hasEmoji("nice to meet you."); // false (no emoji)
validator.hasEmoji("hello, world! 🎉"); // true
validator.hasEmoji("😃😆🥰"); // true
validator.hasEmoji("✅"); // true

Emoji definition

I propose using Unicode's RGI (Recommended for General Interchange) emoji set, with the supported Unicode version documented. https://unicode.org/reports/tr51/

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions