| Crates.io | iranianbank |
| lib.rs | iranianbank |
| version | 0.1.0 |
| created_at | 2025-12-10 17:38:52.998138+00 |
| updated_at | 2025-12-10 17:38:52.998138+00 |
| description | A comprehensive Rust library for validating Iranian bank cards and IBANs (Sheba). |
| homepage | https://github.com/farshadsharifi/iranianbank |
| repository | https://github.com/farshadsharifi/iranianbank |
| max_upload_size | |
| id | 1978501 |
| size | 19,104 |
A comprehensive, high-performance, and zero-dependency Rust library for validating and generating Iranian bank information.
iranianbank provides a robust set of tools to handle Iranian banking data, including Card number validation (Luhn algorithm), IBAN (Sheba) generation and validation, and bank identification.
توضیحات فارسی: کتابخانهای جامع، سریع و بدون وابستگی در زبان راست (Rust) برای اعتبارسنجی و تولید اطلاعات بانکی ایران. این کتابخانه ابزارهایی برای بررسی صحت شماره کارت، تولید و اعتبارسنجی شبا و شناسایی بانکها را فراهم میکند.
Add this to your Cargo.toml:
[dependencies]
iranianbank = "0.1.0"
Verify if a card number is valid based on the checksum algorithm.
use iranianbank::validate_card;
fn main() {
let card = "6037997556165554"; // Example Melli Bank card
match validate_card(card) {
Ok(_) => println!("✅ Card is valid."),
Err(e) => println!("❌ Invalid card: {}", e),
}
}
Parse an IBAN string to check its validity (length, prefix, and checksum) and extract the bank details.
use iranianbank::{Iban, Bank};
fn main() {
let raw_iban = "IR720170000000225264111007";
match Iban::parse(raw_iban) {
Ok(iban) => {
println!("✅ IBAN is valid.");
// Extract Bank Information
if let Ok(bank) = iban.extract_bank() {
println!("Bank Name: {}", bank.name()); // Output: Melli Bank
println!("Bank Code: {}", bank.code()); // Output: 017
}
},
Err(e) => println!("❌ Invalid IBAN: {}", e),
}
}
You can generate a valid IBAN if you have the bank, account type, and account number.
use iranianbank::{Iban, Bank};
fn main() {
let bank = Bank::Melli;
let account_type = '0'; // Usually '0' for deposits (سپرده)
let account_number = "225264111007";
match Iban::new(bank, account_type, account_number) {
Ok(iban) => println!("Generated IBAN: {}", iban.as_str()),
Err(e) => println!("Error generating IBAN: {}", e),
}
}
Convert between bank codes and the Bank enum.
use iranianbank::Bank;
fn main() {
// Find bank by code
let bank = Bank::from_code("057").unwrap();
if bank == Bank::Pasargad {
println!("Bank found: {}", bank.name()); // Pasargad Bank
}
}
This library supports a wide range of Iranian banks, including:
Central Bank (بانک مرکزی)
Melli (ملی)
Sepah (سپه)
Saderat (صادرات)
Tejarat (تجارت)
Mellat (ملت)
Pasargad (پاسارگاد)
Parsian (پارسیان)
Saman (سامان)
Ayandeh (آینده)
And more...
This project is licensed under the MIT License.
Developed by Farshad Sharifi. Contributions are welcome! Please open an issue or submit a pull request on GitHub.