Persian input
One component for all Persian data: national ID, company ID, mobile, landline, card, IBAN, price, postal code, time, licence plate, cheque Sayad ID, economic code, invoice tax ID and text with keyboard-layout correction.
import { PersianInput } from "@kashi-ui/react";
Example
kind="iban"
<PersianInput kind="iban" name="iban" />
<PersianInput kind="price" min={10000} />
<PersianInput kind="postal" label="کد پستی محل کار" />
<PersianInput kind="text" label="جستجو" /> {/* با پیشنهاد «sghl» ← «سلام» */}Instead of remembering the names of fourteen components, build one field with kind. Each kind has its own Persian label, format, validation and error message. The other props are those of the specialised component, and TypeScript suggests them based on kind. For example, showBank is only allowed for card and iban.
| kind | Data | Specialised component |
|---|---|---|
text |
Text with keyboard-layout correction | KeyboardFixInput |
national-id |
National ID (کد ملی) | NationalIdInput |
legal-id |
Company national ID | LegalIdInput |
mobile |
Mobile number with operator | MobileInput |
landline |
Landline with province | LandlineInput |
card |
Card number with bank | CardNumberInput |
iban |
IBAN (Sheba) with bank | IbanInput |
price |
Amount in words | PriceInput |
postal |
Postal code | PostalCodeInput |
time |
Time | TimeInput |
plate |
Car licence plate | PlateInput |
sayad |
Cheque Sayad ID | SayadInput |
economic-code |
Invoice economic code | EconomicCodeInput |
tax-id |
Invoice tax ID (Moadian) | TaxIdInput |
If you give no label, the default label of the kind is used (“شمارهٔ شبا”, “کد پستی” and so on). With aria-label the label is not shown. The list of labels is in PERSIAN_INPUT_LABELS.
Bundle size
PersianInput imports all fourteen fields. If a page needs only one, import the specialised component directly to load less code.
| Name | Description, type and default |
|---|---|
kind | Kind of data |
… | Props of the specialised component for that kind |
Props of each kind
The sections below show the example and the specific props of each kind. Every kind also accepts the Input props such as label, hint, error, required and disabled.
National ID field
A national ID (کد ملی) field with check-digit validation; it accepts Persian and Latin digits.
<PersianInput kind="national-id" /> // یا مستقیم: <NationalIdInput />
A valid test national ID: 0013542419. Change the last digit to see the error.
۱۰ رقم؛ ارقام فارسی و انگلیسی هر دو پذیرفته میشوند.
0 از ۱۰ رقم
<PersianInput kind="national-id"
label="کد ملی"
name="nationalId"
onValueChange={(value, valid) => console.log(value, valid)}
/>Behaviour
- Digits: the user can type with a Persian or an English keyboard. The display uses Persian digits (
digits="latin"for English), but the value is always given to you in English digits. - Limits: every non-digit character is removed and more than 10 digits are not accepted. On phones, the numeric keyboard opens.
- Validation: the tenth digit is checked with the official check-digit algorithm. The error message shows only after the user leaves the field or completes 10 digits, not while typing.
- Forms: with
name, the value is submitted in English digits in a hidden field.
Check-digit validation only shows that the structure of the code is correct, not that it exists. To verify identity, check the code with the official service.
Props
| Name | Description, type and default |
|---|---|
value | Controlled value in English digits |
defaultValue | Initial value |
onValueChange | On every change |
digits | Script of the displayed digits |
invalidMessage | Error message |
name | Name of the hidden form field |
All Input props such as label, hint, error and required are supported too.
Without React
isValidNationalId("۰۰۱۳۵۴۲۴۱۹"); // true
isValidNationalId("1111111111"); // false
Accessibility
- The error is connected to the field with
aria-invalidandaria-describedby. - The field uses
dir="ltr"so the order of the digits does not shift while typing.
Company national ID
The 11-digit national ID of legal entities, with check-digit validation.
<PersianInput kind="legal-id" /> // یا مستقیم: <LegalIdInput />
۱۱ رقم؛ مثلاً ۱۰۳۸۰۲۸۴۷۹۰
هنوز چیزی وارد نشده.
<PersianInput kind="legal-id" label="شناسهٔ ملی شرکت" name="legalId"
onValueChange={(value, valid) => …} />The national ID of companies, institutions and organisations has 11 digits, and the last one is a check digit. It is needed in B2B forms, official invoices and seller registration on marketplaces. Persian and English digits are accepted. Without React it is available as isValidLegalId from @kashi-ui/persian:
isValidLegalId("10380284790"); // true
| Name | Description, type and default |
|---|---|
value / defaultValue | Latin digits |
onValueChange | |
digits | |
invalidMessage | |
name | Hidden field with 11 Latin digits |
Accessibility
The error shows after the user leaves the field or completes 11 digits, and is connected to the field with aria-describedby.
Mobile number
An Iranian mobile number field with automatic +98 conversion, grouping and operator detection.
<PersianInput kind="mobile" /> // یا مستقیم: <MobileInput />
Type or paste the number in any form: 09123456789, +98 912 345 6789 or 00989123456789.
+98 و 0098 هم پذیرفته میشود.
<PersianInput kind="mobile"
label="شماره موبایل"
name="mobile"
onValueChange={(mobile, valid, operator) => console.log(mobile, valid, operator)}
/>Behaviour
- Normalisation:
+98,0098,98and a number without the leading zero (912…) become the standard09xxxxxxxxx. - Operator: MCI (Hamrah-e Avval), Irancell and Rightel are detected from the prefix. Because numbers can be ported between operators, the operator is only a hint.
- Keyboard: on phones the phone keypad opens, and the browser can suggest the saved number.
Props
| Name | Description, type and default |
|---|---|
value | Controlled value, in any form |
defaultValue | Initial value |
onValueChange | Value in the form 09xxxxxxxxx |
digits | Script of the displayed digits |
showOperator | Show the operator name |
invalidMessage | Error message |
name | Name of the hidden form field |
Without React
normalizeMobile("+98 912 345 6789"); // "09123456789"
getMobileOperator("0935")?.name; // "ایرانسل"
formatMobile("09123456789"); // "0912 345 6789"
Landline number
A landline number with area code, grouping and province detection.
<PersianInput kind="landline" /> // یا مستقیم: <LandlineInput />
با پیششماره؛ +98 هم پذیرفته میشود
مثلاً ۰۳۱۳۲۲۲۱۱۰۰ را امتحان کنید.
<PersianInput kind="landline" label="تلفن ثابت" name="tel"
onValueChange={(value, valid, province) => …} />+98 and 0098 are converted to 0, and the province name is shown next to the field from the three-digit area code (such as 031 for Isfahan). The area codes of all 31 provinces are in getLandlineProvince.
| Name | Description, type and default |
|---|---|
value / defaultValue | For example 02188776655 |
onValueChange | |
showProvince | Province name next to the field |
digits | |
invalidMessage | |
name | Hidden field with 11 Latin digits |
Accessibility
The province name is connected to the field with aria-describedby. autocomplete="tel-national" and the phone’s numeric keypad are enabled.
Card number
A bank card number field with automatic grouping, bank detection and Luhn validation.
<PersianInput kind="card" /> // یا مستقیم: <CardNumberInput />
Type the first six digits, for example 603799 or 610433, to see the bank logo and name.
با تایپ شش رقم اول، نام بانک نمایش داده میشود.
<PersianInput kind="card"
label="شماره کارت"
name="card"
onValueChange={(value, valid, bank) => console.log(value, valid, bank)}
/>Behaviour
- Grouping: digits are shown automatically in groups of four. When you edit the middle of the number, the cursor stays in the right place.
- Pasting: a number copied with spaces, hyphens or Persian digits is read correctly too.
- Bank detection: the bank logo and name are detected from the first six digits (BIN). Logos are loaded only when the bank is recognised, so they do not add to the initial bundle (bank logos). The list of banks may be incomplete; use it only as a hint for the user.
- Validation: the 16-digit number is checked with the Luhn algorithm.
- Autofill: with
autocomplete="cc-number", the browser can suggest a saved card.
This field only formats the number in the browser. A card number is sensitive data; send it only over HTTPS and do not store it unless you need to.
Props
| Name | Description, type and default |
|---|---|
value | Controlled value: 16 English digits without spaces |
defaultValue | Initial value |
onValueChange | On every change |
digits | Script of the displayed digits |
showBank | Show the bank name |
showBankLogo | Show the bank logo (lazy loaded) |
invalidMessage | Error message |
name | Name of the hidden form field, with digits and no spaces |
Without React
formatCardNumber("6037991234567890"); // "6037 9912 3456 7890"
getBankByCard("603799")?.name; // "بانک ملی"
isValidCardNumber("4111 1111 1111 1111"); // true
Accessibility
- The bank name is connected to the field with
aria-describedby, and screen readers read it together with the field. - The error shows after the user leaves the field or completes 16 digits, not while typing.
IBAN (Sheba)
An Iranian IBAN (Sheba) field with automatic IR prefix, grouping, bank logo and name, and check-digit validation.
<PersianInput kind="iban" /> // یا مستقیم: <IbanInput />
Type only the digits; “IR” is added automatically. When you type digits 3 to 5 (the bank code), the bank logo and name are shown.
بعد از ۵ رقم اول، بانک تشخیص داده میشود.
<PersianInput kind="iban"
label="شماره شبا"
name="iban"
onValueChange={(iban, valid, bank) => console.log(iban, valid, bank)}
/>Behaviour
- Free input: an IBAN is accepted with or without “IR”, with or without spaces, and with Persian or English digits.
- Validation: the check digits are verified with ISO 13616 (remainder 97); any wrong digit or swap of adjacent digits is detected.
- Value: always given to you as
IRplus 24 digits with no spaces. - Digits: an IBAN is usually written in English digits; pass
digits="fa"for Persian digits.
Props
| Name | Description, type and default |
|---|---|
value | Controlled IBAN, with or without IR |
defaultValue | Initial value |
onValueChange | On every change |
digits | Script of the displayed digits |
showBank | Show the bank name |
showBankLogo | Show the bank logo (lazy loaded) |
invalidMessage | Error message |
name | Name of the hidden form field with the value IR… |
Without React
isValidIban("IR06 2960 0000 0010 0324 2000 01");
getBankByIban("IR..0170...")?.name; // "بانک ملی"
formatIban("062960000000100324200001"); // "IR06 2960 0000 0010 0324 2000 01"
Accessibility
- The bank name is connected to the field with
aria-describedby; the logo is decorative (alt="") so screen readers do not read the bank name twice.
Price field
An amount field with a Persian thousands separator, a currency unit and the amount shown in words.
<PersianInput kind="price" /> // یا مستقیم: <PriceInput />
The amount in words is shown under the field so the user can be sure they entered the zeros correctly, a common and costly mistake in payments.
یک میلیون و دویست و پنجاه هزار تومان
مقدار عددی: 1,250,000
<PersianInput kind="price"
label="مبلغ پرداخت"
name="amount"
max={500_000_000}
onValueChange={(amount) => console.log(amount)}
/>Behaviour
- Formatting: the Persian thousands separator (
٬) is added while typing, and the cursor stays in place. - In words: “یک میلیون و دویست و پنجاه هزار تومان” (one million two hundred and fifty thousand tomans). Turn it off with
showWords={false}. - Unit: “تومان” (toman) by default; change it with
unit="ریال"(rial) or any other text. - Value: a number, or
nullfor an empty field. Leading zeros are removed. Up to 15 digits. - Range: with
minandmax, an error message shows after the user leaves the field.
Props
| Name | Description, type and default |
|---|---|
value | Controlled value |
defaultValue | Initial value |
onValueChange | On every change |
unit | Currency unit next to the field |
showWords | Show the amount in words in the hint text |
min / max | Allowed range |
rangeMessage | Range error message |
digits | Script of the displayed digits |
name | Name of the hidden form field with the raw numeric value |
Without React
numberToWords(1250000); // "یک میلیون و دویست و پنجاه هزار"
formatNumber(1250000); // "۱٬۲۵۰٬۰۰۰"
Accessibility
- The amount in words is in the hint text and is connected to the field with
aria-describedby; screen readers read it after the field name. - The currency unit is shown next to the field; repeat it in the label if it is needed to understand the field.
Postal code
An Iranian 10-digit postal code in the format 12345-67890, with its rules checked.
<PersianInput kind="postal" /> // یا مستقیم: <PostalCodeInput />
۱۰ رقم، بدون خط تیره هم میشود
مثلاً ۱۱۹۳۶۵۳۴۷۱ را امتحان کنید.
<PersianInput kind="postal" label="کد پستی" name="postal"
onValueChange={(value, valid) => …} />Persian and English digits are accepted and the hyphen is added automatically. An Iranian postal code has no 0 or 2 in its first five digits and no four identical digits in a row; isValidPostalCode checks these rules. This check does not guarantee that the code really exists.
| Name | Description, type and default |
|---|---|
value / defaultValue | Latin digits |
onValueChange | |
digits | |
invalidMessage | |
name | Hidden field with 10 Latin digits |
Accessibility
It has autocomplete="postal-code" so the browser can fill it in. The error shows after the user leaves the field or completes 10 digits, not while typing.
Time field
24-hour time entry with Persian digits, quick typing and ↑↓ steps.
<PersianInput kind="time" /> // یا مستقیم: <TimeInput />
The user can type “۹۳۰”, “۹:۳۰” or “9.30”; after leaving the field it becomes “۰۹:۳۰”. ↑/↓ jump to the next or previous step.
بین ۰۸:۰۰ تا ۲۰:۰۰؛ ↑↓ هر ۱۵ دقیقه
مقدار ارسالی فرم: 09:30
<PersianInput kind="time" label="ساعت شروع جلسه" min="08:00" max="20:00" value={t} onChange={setT} name="start" />| Name | Description, type and default |
|---|---|
value / defaultValue | In Latin digits |
onChange | |
step | ↑↓ step in minutes |
min / max | Allowed range |
digits | |
invalidMessage | Message for an invalid time |
rangeMessage | Message for a time outside the range |
The parseTime and formatTime helpers are also available in @kashi-ui/persian.
Accessibility
A plain text field with a label and hint; unlike <input type="time">, it works the same in every browser and with Persian digits. The error shows after the user leaves the field and is connected to it.
Licence plate
Entry of an Iranian car licence plate that looks like the real plate: two digits, a letter, three digits and the province code.
<PersianInput kind="plate" /> // یا مستقیم: <PlateInput />
با پر شدن هر بخش، فوکوس به بخش بعد میرود.
پلاک را کامل وارد کنید.
<PersianInput kind="plate" label="پلاک خودرو" name="car"
onChange={(plate, valid) => …} />
// plate = { first: "12", letter: "ب", middle: "345", region: "67" }The plate has the real 520 by 110 mm proportion, and its colour is set from the letter, like a real plate (plateType):
| Letter | Type | Colour |
|---|---|---|
| ب, ج, د, س… | Private | White |
| ت / ع / ک | Taxi / public / agricultural | Yellow |
| الف | Government | Red |
| پ / ث | Police / IRGC | Green |
| ش | Army | Light brown |
| ز / ف | Ministry of Defence / General Staff | Light blue |
| ژ | People with disabilities | White |
The height changes with --k-plate-height (default 3.5rem) and the width changes in proportion. When a part is full, focus moves to the next part, and Backspace in an empty part goes back to the previous one. formatPlate produces readable text: “۱۲ ب ۳۴۵ ایران ۶۷”.
| Name | Description, type and default |
|---|---|
value / defaultValue | Latin digits |
onChange | |
name | Four hidden fields: name_first, name_letter, name_middle, name_region |
labels | Name of each part for screen readers |
invalidMessage |
Accessibility
A role="group" named “پلاک خودرو” (car licence plate) and four controls, each with its own name (“دو رقم اول پلاک”, “حرف پلاک”…). The letter is chosen with a native <select>. When the plate is complete and valid, its full text is read with aria-live.
Cheque Sayad ID
The 16-digit ID printed at the bottom of every Iranian cheque leaf, in groups of four.
<PersianInput kind="sayad" /> // or directly: <SayadInput />
۱۶ رقم پایین برگهٔ چک
<PersianInput kind="sayad" name="sayad" hint="۱۶ رقم پایین برگهٔ چک" />Registering, confirming or transferring a cheque in the Sayad system needs this ID. Its check-digit algorithm is not public, so the field only checks that it has 16 digits; verify the cheque itself with the Sayad system.
isValidSayad("1234 5678 9012 3456"); // true
formatSayad("1234567890123456"); // "1234 5678 9012 3456"
| Name | Description, type and default |
|---|---|
value / defaultValue | Latin digits |
onValueChange | |
digits | |
invalidMessage | |
name | Hidden field with 16 Latin digits, no spaces |
Economic code
The buyer’s or seller’s economic code on an official invoice, with the type shown next to the field.
<PersianInput kind="economic-code" /> // or directly: <EconomicCodeInput />
<PersianInput kind="economic-code" label="کد اقتصادی خریدار"
onValueChange={(value, valid, type) => …} /> // type: "person" | "company" | "legacy"Since 1398 (2019) the economic code of an individual is their national ID (10 digits) and that of a company is its national ID (11 digits); both are checked with their own check digit. The old 12-digit code still appears on older invoices and is checked for length only.
isValidEconomicCode("10380284790"); // true
economicCodeType("0499370899"); // "person"
| Name | Description, type and default |
|---|---|
value / defaultValue | Latin digits |
onValueChange | |
showType | Show the code type next to the field |
digits | |
invalidMessage | |
name | Hidden field with Latin digits |
Invoice tax ID
The unique tax ID of an e-invoice in the Moadian system, 22 characters.
<PersianInput kind="tax-id" /> // or directly: <TaxIdInput />
از سامانهٔ مودیان
<PersianInput kind="tax-id" name="taxId" hint="از سامانهٔ مودیان" />Letters become uppercase, Persian digits become Latin, and spaces and dashes are removed, so a pasted ID always fits. Only the shape (22 Latin letters and digits) is checked; only the Moadian system can confirm the ID itself.
normalizeTaxId("a11 2b3-۴۵"); // "A112B345"
isValidTaxId(taxId); // 22 allowed characters?
| Name | Description, type and default |
|---|---|
value / defaultValue | Uppercase letters and Latin digits |
onValueChange | |
invalidMessage | |
name | Hidden field with the normalised value |
Accessibility
All three fields show their error after the user leaves the field or completes the length, connected with aria-describedby. The economic-code type is connected to the field too, so screen readers read it.
Keyboard-layout correction
If the user types Persian with an English keyboard layout, it suggests the right form: sghl → سلام.
<PersianInput kind="text" /> // یا مستقیم: <KeyboardFixInput />
منظورتان بود؟
مقدار: sghl o,fd?
<PersianInput kind="text" label="جستجو" value={query} onValueChange={setQuery} />Persian speakers often forget to switch the keyboard language and type “سلام” as “sghl”. This field suggests the Persian form under the field and replaces it with one click. It is most useful for search.
Detection is a heuristic by default (suggest="auto"): Latin words with no vowels, or with ;, ' and [ in the middle of a word, are suspicious. To suggest for any Latin text, use suggest="always". The conversion is based on the standard Persian keyboard layout.
fixKeyboardLayout("sghl o,fd?"); // "سلام خوبی؟"
fixKeyboardLayout("لخخلمث", "en"); // "google"
looksLikeWrongLayout("sghl"); // true
| Name | Description, type and default |
|---|---|
value / defaultValue | |
onValueChange | |
suggest | |
renderSuggestion | Custom suggestion text |
Accessibility
The suggestion is in a role="status" region so screen readers announce it, and its button is reachable by keyboard. After the replacement, focus returns to the field.