I need a method to validate the Melli Code (National Code or Code Melli) of iranian people.
I Know it has a formula.
You can validate your national code like this:
public static boolean isValidNationalCode(String nationalCode)
{
if (!nationalCode.matches("^\\d{10}$"))
return false;
int sum = 0;
for (int i = 0; i < 9; i++)
{
sum += Character.getNumericValue(nationalCode.charAt(i)) * (10 - i);
}
int lastDigit = Integer.parseInt(String.valueOf(nationalCode.charAt(9)));
int divideRemaining = sum % 11;
return ((divideRemaining < 2 && lastDigit == divideRemaining) || (divideRemaining >= 2 && (11 - divideRemaining) == lastDigit ));
}