Saudi forms and dates
PlateInput
One field for a car plate: letters and digits in any order, Arabic or Latin letters, Western or Arabic digits. A live plate shows under it. A letter that is not on plates, more than 3 letters or more than 4 digits shows what to fix. Keep the text, and store the result of parsePlate(): Arabic letters and Western digits, leading zeros kept.
import { PlateInput, parsePlate, plateIssueMessage, type ParsedPlate, type PlateIssue } from "@percentsa/ui";Examples
Letters and digits in any order, Arabic or English.
Stored as: —
Code
export function PlateInputExample() {
const t = useT();
const [text, setText] = useState("");
const plate = parsePlate(text);
return (
<Stack gap={3} className="w-full max-w-sm">
<Field label={t("Car plate", "لوحة السيارة")}>
<PlateInput value={text} onValueChange={setText} name="plate" />
</Field>
<Text size="sm" tone="subtle">
{t("Stored as: ", "يُحفظ كالتالي: ")}
<span dir="ltr">{plate.ok && !plate.empty ? `${plate.letters} ${plate.digits}` : "—"}</span>
</Text>
</Stack>
);
}