I need a method to validate the Melli Code (National Code or Code Melli) of iranian people.
I Know it has a formula.
I have so many different versions of it here but the following is its Kotlin version,
fun isValidIranianNationalCode(input: String): Boolean {
if (!"^\\d{10}$".toRegex().matches(input))
return false
input.toCharArray().map(Character::getNumericValue).let {
val check = it[9]
val sum = (0..8).map { i -> it[i] * (10 - i) }.sum() % 11
return sum < 2 && check == sum || sum >= 2 && check + sum == 11
}
}