Skip to main content

SHEBA/IBAN Validation

Validate Iranian IBAN numbers (SHEBA) and extract bank information.

Available Functions

  • verifySheba - Validate SHEBA number
  • getShebaInfo - Get bank details from SHEBA

Basic Usage

import { verifySheba, getShebaInfo } from "@persian-tools/persian-tools";

// Validate SHEBA
console.log(verifySheba("IR820540102680020817909002"));
// Output: true

// Get bank info
console.log(getShebaInfo("IR820540102680020817909002"));
// Output: { bankName: 'بانک پارسیان', formatted: 'IR82 0540 1026 8002 0817 9090 02' }

API Reference

verifySheba

Validate an Iranian SHEBA/IBAN number.
sheba
string
required
SHEBA number (with or without IR prefix)
result
boolean
true if valid, false otherwise
verifySheba("IR820540102680020817909002"); // true
verifySheba("820540102680020817909002"); // true (without IR)
verifySheba("IR00000000000000000000000000"); // false

getShebaInfo

Extract bank information from a SHEBA number.
sheba
string
required
Valid SHEBA number
result
object
Bank information object

Examples

Payment Transfer

import { verifySheba, getShebaInfo } from "@persian-tools/persian-tools";

const initiateTransfer = (sheba: string, amount: number) => {
	if (!verifySheba(sheba)) {
		throw new Error("شماره شبا نامعتبر است");
	}

	const bankInfo = getShebaInfo(sheba);

	return {
		recipient: bankInfo.formatted,
		bank: bankInfo.bankName,
		amount,
	};
};

console.log(initiateTransfer("IR820540102680020817909002", 1000000));
// {
//   recipient: 'IR82 0540 1026 8002 0817 9090 02',
//   bank: 'بانک پارسیان',
//   amount: 1000000
// }

Form Validation

import { verifySheba } from "@persian-tools/persian-tools";

const validateShebaInput = (
	input: string,
): {
	isValid: boolean;
	error?: string;
} => {
	// Remove spaces and normalize
	const cleaned = input.replace(/\s/g, "").toUpperCase();

	if (!cleaned.startsWith("IR") && cleaned.length !== 24) {
		return {
			isValid: false,
			error: "شماره شبا باید ۲۶ کاراکتر باشد",
		};
	}

	if (!verifySheba(cleaned)) {
		return {
			isValid: false,
			error: "شماره شبا نامعتبر است",
		};
	}

	return { isValid: true };
};

Use Cases

Validate recipient accounts:
const processPayment = (recipientSheba: string) => {
  if (!verifySheba(recipientSheba)) {
    throw new Error('Invalid SHEBA');
  }
  // Process payment
};
Validate employee bank accounts:
const addEmployeeAccount = (sheba: string) => {
  if (!verifySheba(sheba)) {
    throw new Error('شماره شبا کارمند نامعتبر است');
  }
  return getShebaInfo(sheba);
};

SHEBA Format

Iranian SHEBA numbers follow this format:
  • IR - Country code
  • 2 digits - Check digits
  • 3 digits - Bank code
  • 19 digits - Account number
Total: 26 characters

Type Definition

interface ShebaInfo {
	bankName: string;
	formatted: string;
}

function verifySheba(sheba: string): boolean;
function getShebaInfo(sheba: string): ShebaInfo;