Skip to content

Instantly share code, notes, and snippets.

@HudiDev
Created June 6, 2019 07:43
Show Gist options
  • Save HudiDev/4f740ecb5d95ddd7f8214a4360e27a17 to your computer and use it in GitHub Desktop.
Save HudiDev/4f740ecb5d95ddd7f8214a4360e27a17 to your computer and use it in GitHub Desktop.
Isreali ID Validator (swift)
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