Documentation Index
Fetch the complete documentation index at: https://persian-tools.usestrict.dev/llms.txt
Use this file to discover all available pages before exploring further.
Legal ID Validation
Validate Iranian legal entity identification numbers (شناسه حقوقی) used for companies and organizations.
Basic Usage
import { verifyIranianLegalId } from "@persian-tools/persian-tools";
console.log(verifyIranianLegalId("10320166911"));
// Output: true
console.log(verifyIranianLegalId("12345678901"));
// Output: false
API Reference
The 11-digit legal entity ID to validate
true if valid, false otherwise
Examples
Company Registration Validation
import { verifyIranianLegalId } from "@persian-tools/persian-tools";
interface CompanyValidation {
isValid: boolean;
errors: string[];
}
const validateCompany = (legalId: string): CompanyValidation => {
const errors: string[] = [];
if (!legalId || legalId.length !== 11) {
errors.push("شناسه حقوقی باید ۱۱ رقم باشد");
}
if (!/^\d+$/.test(legalId)) {
errors.push("شناسه حقوقی فقط باید شامل اعداد باشد");
}
if (!verifyIranianLegalId(legalId)) {
errors.push("شناسه حقوقی نامعتبر است");
}
return {
isValid: errors.length === 0,
errors,
};
};
console.log(validateCompany("10320166911"));
// { isValid: true, errors: [] }
import { verifyIranianLegalId } from "@persian-tools/persian-tools";
const verifyBusinessPartner = (companyData: { name: string; legalId: string }) => {
if (!verifyIranianLegalId(companyData.legalId)) {
throw new Error("شناسه حقوقی شرکت نامعتبر است");
}
return {
verified: true,
companyName: companyData.name,
legalId: companyData.legalId,
};
};
import { verifyIranianLegalId, digitsFaToEn } from "@persian-tools/persian-tools";
const validateLegalIdInput = (input: string): boolean => {
// Convert Persian digits to English
const normalized = digitsFaToEn(input.trim());
// Check length
if (normalized.length !== 11) {
return false;
}
// Validate checksum
return verifyIranianLegalId(normalized);
};
console.log(validateLegalIdInput("۱۰۳۲۰۱۶۶۹۱۱"));
// true
Use Cases
Validate company information during B2B registration:const registerBusiness = (data: any) => {
if (!verifyIranianLegalId(data.legalId)) {
throw new Error('شناسه حقوقی معتبر نیست');
}
// Proceed with registration
};
Verify legal IDs on invoices:const validateInvoice = (invoice: any) => {
const isValid = verifyIranianLegalId(invoice.sellerLegalId);
if (!isValid) {
throw new Error('شناسه حقوقی فروشنده نامعتبر است');
}
};
Ensure tax-related documents have valid legal IDs:const validateTaxDocument = (legalId: string) => {
return {
isValid: verifyIranianLegalId(legalId),
message: verifyIranianLegalId(legalId)
? 'شناسه معتبر است'
: 'شناسه نامعتبر است'
};
};
Validation Algorithm
The Iranian legal ID uses an 11-digit format with a checksum digit calculated using a specific algorithm similar to the national ID validation.
National ID Validation
Validate personal national IDs
Card Number Validation
Validate bank card numbers
Type Definition
function verifyIranianLegalId(legalId: string): boolean;
Legal IDs are 11 digits long, whereas personal national IDs are 10 digits long.