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.
- Bank Utils
- NationalId Utils
- Text Utils
- Convert Persian words to the number
- Convert Numbers to Persian words
- Fix Persian characters in URL
- Fix Persian zero-width non-joiner (Replace spaces by half-space)
- Validate the correctness of the text of the Persian language and clear the Arabic letters in the Persian text
- Digit Utils
- Convert Persian numbers to Arabic or English numbers and vice versa
- Add and remove commas to numbers
- Date Utils
- Convert Jalaali date-time into a time ago
- Miscellaneous
- Validate Iranian legal id (shenase hoghoghi)
- Bill calculator
- Validate and find information of phone number
- upload artifact to Maven Central Repository
Let's take a look at what an example test case would look like using java-persian-tools.
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 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
boolean isValid = BankUtils.isValidCardNumber("6037701689095443"); //true
boolean isValid = BankUtils.isValidCardNumber("6219861034529008"); //false
boolean isValid = BankUtils.isValidIban("IR820540102680020817909002"); //true
boolean isValid = BankUtils.isValidIban("IR012345678901234567890123"); //false
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
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
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); //منفی صد و بیست و سوم
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.
java-persian-tools
is available under the MIT license.