Skip to content

Latest commit

 

History

History
112 lines (91 loc) · 5.34 KB

README.md

File metadata and controls

112 lines (91 loc) · 5.34 KB

Java Persian tools

This repository is java port of persian-tools

PersianTools is a standalone, library-agnostic Java that enables some of the Persian features for use in the Java.


Features

Install

  • upload artifact to Maven Central Repository

Usage

Let's take a look at what an example test case would look like using java-persian-tools.

Find bank information by card number

Find the issuer bank of the card number. Throws BankNotFoundByProvidedCardNumber if the card number is not valid or no bank found.

Bank bank = BankUtils.findByCardNumber("6037701689095443"); // { persianName: 'بانک کشاورزی', name: 'Keshavarzi', nickname: 'keshavarzi', ... }
Bank bank = BankUtils.findByCardNumber("621986103452900"); // throws BankNotFoundByProvidedCardNumber

Find bank information by IBAN (sheba)

Find the issuer bank of the IBAN. Throws BankNotFoundByProvidedIban if the IBAN is not valid or no bank found.

Bank bank = BankUtils.findByIban("IR550570022080013447370101"); // { persianName: 'بانک پاسارگاد', name: 'Pasargad Bank', nickname: 'pasargad', ... }
Bank bank = BankUtils.findByCardNumber("IR820540102680020817909001"); // throws BankNotFoundByProvidedIban

Validate card number

boolean isValid = BankUtils.isValidCardNumber("6037701689095443"); //true
boolean isValid = BankUtils.isValidCardNumber("6219861034529008"); //false

Validate IBAN

boolean isValid = BankUtils.isValidIban("IR820540102680020817909002"); //true
boolean isValid = BankUtils.isValidIban("IR012345678901234567890123"); //false

Validate Iranian national id (code-e melli)

Check whether the provided National-id is valid or not. In case of missing starting zeros (max 2 zeros) it will pad the input with "0". It throws IllegalArgumentException when the input is null or empty.

boolean isValid = NationalIdUtils.verifyIranianNationalId("0499370899"); //true
boolean isValid = NationalIdUtils.verifyIranianNationalId("67749828"); //true
boolean isValid = NationalIdUtils.verifyIranianNationalId("1111111111"); //true
boolean isValid = NationalIdUtils.verifyIranianNationalId("0684159415"); //false
boolean isValid = NationalIdUtils.verifyIranianNationalId("0000000000"); //false
boolean isValid = NationalIdUtils.verifyIranianNationalId(null); //throws IllegalArgumentException

Find birthplace by national id

Returns a list of possible birthplaces for provided national id. Returns empty list if provided national id is invalid and throws IllegalArgumentException if the input is null or empty.

List<Hometown> hometowns = NationalIdUtils.getPlaceByIranNationalId("0084575948"); // [{ province: 'تهران', city: 'تهران مرکزی' }]
List<Hometown> hometowns = NationalIdUtils.getPlaceByIranNationalId("2530000000"); // [{ province: 'فارس', city: 'اقلید' },{ province: 'فارس', city: 'سپیدان' }]
List<Hometown> hometowns = NationalIdUtils.getPlaceByIranNationalId("0008454594"); // []
List<Hometown> hometowns = NationalIdUtils.getPlaceByIranNationalId(null); //throws IllegalArgumentException

Convert Numbers to Persian words

String result = NumberUtils.numberToWords(4); //چهار
String result = NumberUtils.numberToWords(0); //صفر
String result = NumberUtils.numberToWords(30000000000L); //سی میلیارد
String result = NumberUtils.numberToWords(500443); //پانصد هزار و چهار صد و چهل و سه

// with ordinal = true
String result = NumberUtils.numberToWords(-30, true); //منفی سی اُم
String result = NumberUtils.numberToWords(-123, true); //منفی صد و بیست و سوم

Contributing

Thank you for your interest in contributing to Java Persian Tools. Contributions are welcome and please feel free to put up a PR for any issue or feature request.

License

java-persian-tools is available under the MIT license.