Skip to content
العربية
Saudi and bilingual kit

Validators

Checks for Saudi numbers. They accept spaces and Arabic digits, and work on the server.

import { isSaudiIban, isNationalId, getSaudiIdType, isCrNumber, isVatNumber, isShortAddress, saudiError } from "@percentsa/ui";

Examples

  • ✓ IBAN
  • ✗ National ID
  • ✗ CR
  • ✗ VAT

SA03 8000 0000 6080 1016 7519

Code
export function ValidatorsExample() {
  const t = useT();
  const [value, setValue] = useState("SA0380000000608010167519");
  const checks = [
    ["IBAN", isSaudiIban(value)],
    [t("National ID", "رقم الهوية"), isNationalId(value)],
    [t("CR", "السجل التجاري"), isCrNumber(value)],
    [t("VAT", "الرقم الضريبي"), isVatNumber(value)],
  ] as const;
  return (
    <Stack gap={4} className="w-full max-w-sm">
      <Field label={t("Any number", "أي رقم")}>
        <Input dir="ltr" value={value} onChange={(e) => setValue(e.target.value)} className="font-mono" />
      </Field>
      <ul className="grid gap-1 text-sm">
        {checks.map(([name, ok]) => (
          <li key={name} className={ok ? "text-fg" : "text-fg-3"}>
            {ok ? "✓" : "✗"} {name}
          </li>
        ))}
      </ul>
      {isSaudiIban(value) && <Text size="sm" tone="muted" dir="ltr">{formatIban(value)}</Text>}
    </Stack>
  );
}