Created
June 6, 2019 07:43
-
-
Save HudiDev/4f740ecb5d95ddd7f8214a4360e27a17 to your computer and use it in GitHub Desktop.
Isreali ID Validator (swift)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
func israeliIDValidator(idNum: String) -> Bool { | |
guard Int(idNum) != nil else { return false } | |
return ("00000000" + idNum).suffix(9).enumerated().reduce(0) { | |
let step = Int(String($1.1))! * ($1.0 % 2 + 1) | |
return $0 + (step > 9 ? step - 9 : step) | |
} % 10 == 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment