Alireza Noorali
Alireza Noorali

Reputation: 3265

How to validate National Identity (Shenaseh Meli) of Iranian legal people

I need a method to validate the National Identity of Iranian legal people.

I have National Code validation method of Iranian natural people HERE, but now I need National ID validation of Iranian legal people or companies

Upvotes: 0

Views: 588

Answers (1)

Saleh
Saleh

Reputation: 1931

Here is a function to do so:

private boolean validateNationalOrgId(String nationalNo) {
    int[] MULT = {29, 27, 23, 19, 17, 29, 27, 23, 19, 17};
    int length = nationalNo.length();
    if (StringUtils.isNumeric(nationalNo) && length == 11) {
        char[] chars = nationalNo.toCharArray();
        int checkDigit = Character.getNumericValue(chars[length - 1]);
        int delta = 0;
        int tensPlusTwo = Character.getNumericValue(chars[length - 2]) + 2;
        for (int i = 0; i < length - 1; i++) {
            delta += ((Character.getNumericValue(chars[i]) + tensPlusTwo) * MULT[i]);
        }
        int remain = delta % 11;
        remain = remain == 10 ? 0 : remain;
        return remain == checkDigit;
    }
    return false;
}

Upvotes: 4

Related Questions