I need a method to validate the Melli Code (National Code or Code Melli) of iranian people.
I Know it has a formula.
Java 8
import java.util.stream.Streams;
import java.util.function.IntUnaryOperator;
public static boolean isValidIranianNationalCode(String input) {
if (!input.matches("^\\d{10}$"))
return false;
int check = Integer.parseInt(input.substring(9, 10));
int sum = IntStream.range(0, 9)
.map(x -> Integer.parseInt(input.substring(x, x + 1)) * (10 - x))
.sum() % 11;
return (sum < 2 && check == sum) || (sum >= 2 && check + sum == 11);
}