Emoji-only input
Accept only emoji values in a user profile, reaction, or label field.
Zod ยท Module
z.emoji() validates a single emoji character in current Zod. It accepts complete emoji, including keycap sequences, while rejecting component-only strings such as 123.
In current Zod, z.emoji() is a top-level string-format schema that validates a single emoji character. Parsing succeeds for emoji input and fails for non-emoji text; custom error messages can be supplied through the options object.
z.emoji(options?)| Name | Type | Description |
|---|---|---|
options | object | Options object for configuring the schema, including a custom validation message. |
A Zod schema that validates a single emoji character.
z.emoji() as the dedicated schema for one emoji character.๐ succeeds.import { z } from "zod";
const Emoji = z.emoji();
console.log(Emoji.parse("๐"));
console.log(Emoji.safeParse("hello").success);Creates a schema that accepts a single emoji and rejects ordinary non-emoji text.
Accept only emoji values in a user profile, reaction, or label field.
Reject incomplete Unicode emoji components before storing or displaying user content.
Use a schema parser to validate emoji values at API or form boundaries.
z.emoji() validate?z.emoji() is the current top-level Zod schema for validating a single emoji character. It replaces the legacy chained string form shown in older documentation.
Follow-up: What changed in the migration? String formats became subclasses of ZodString, and formats such as emoji moved to the top-level z namespace.
It accepts a complete emoji such as ๐ and rejects ordinary text such as hello. In the current behavior, component-only strings are also rejected.
Follow-up: Why is 123 rejected even though some characters can participate in emoji sequences? They are components without the required pictograph, regional-indicator, or keycap anchor.
The schema can be constructed directly with z.emoji() and parsed with the normal Zod parsing APIs. The documentation also shows that string-format schemas can be moved to the top-level namespace.
Follow-up: How would you customize the validation error? Pass an options object with a message, for example z.emoji({ message: "Expected an emoji" }).
z.string()z.email()z.url()z.uuid()z.regex()