Saudi forms and dates
NationalIdInput, CrInput, VatInput
National ID or iqama (10 digits, check digit), commercial registration (10 digits), VAT number (15 digits).
import { NationalIdInput, CrInput, VatInput, saudiError } from "@percentsa/ui";Examples
Code
export function IdInputsExample() {
const t = useT();
const lang = useLang();
const [id, setId] = useState("");
// The first digit names the ID (1 national ID, 2 iqama); all 10 digits are checked.
const idError = id.length === 10 && !isNationalId(id) ? saudiError("nationalId", id, lang) : null;
const idHint = idError ? null : id[0] === "1" ? t("National ID", "هوية وطنية") : id[0] === "2" ? t("Iqama", "إقامة") : null;
const [cr, setCr] = useState("");
const [vat, setVat] = useState("");
return (
<Stack gap={6} className="w-full max-w-sm">
<Field label={t("National ID or iqama", "رقم الهوية أو الإقامة")} hint={idHint} error={idError}>
<NationalIdInput value={id} onValueChange={setId} />
</Field>
<Field label={t("Commercial registration", "السجل التجاري")} error={cr.length === 10 ? saudiError("cr", cr, lang) : null}>
<CrInput value={cr} onValueChange={setCr} />
</Field>
<Field label={t("VAT number", "الرقم الضريبي")} error={vat.length === 15 ? saudiError("vat", vat, lang) : null}>
<VatInput value={vat} onValueChange={setVat} />
</Field>
</Stack>
);
}