-
Notifications
You must be signed in to change notification settings - Fork 26
Open
Description
| public override ValidationResult ValidateIndividualTaxCode(string id) | |
| { | |
| if (!Regex.IsMatch(id, "^[0-9]{6}[-+A][0-9]{3}[0-9ABCDEFHJKLMNPRSTUVWXY]$")) | |
| { | |
| return ValidationResult.Invalid("Invalid code"); | |
| } | |
| var day = int.Parse(id.Substring(0, 2)); | |
| var month = int.Parse(id.Substring(2, 2)); | |
| var year = int.Parse(id.Substring(4, 2)); | |
| var centuries = new Dictionary<char, int>(){ | |
| { '+', 1800 }, | |
| { '-', 1900}, | |
| { 'A', 2000} | |
| }; | |
| year = centuries[id[6]] + year; | |
| try | |
| { | |
| DateTime date = new DateTime(year, month, day); | |
| if (date > DateTime.Now) | |
| { | |
| return ValidationResult.InvalidDate(); | |
| } | |
| } | |
| catch | |
| { | |
| return ValidationResult.InvalidDate(); | |
| } | |
| var individual = int.Parse(id.Substring(7, 3)); | |
| if (individual < 2) | |
| { | |
| return ValidationResult.Invalid("Invalid"); | |
| } | |
| var n = id.Substring(0, 6) + id.Substring(7, 3); | |
| long intn = long.Parse(n); | |
| return "0123456789ABCDEFHJKLMNPRSTUVWXY"[(int)intn % 31] == id[10] ? ValidationResult.Success() : ValidationResult.InvalidChecksum(); | |
| } |
There are new separator characters being introduced in addition to -, + and A.
More information and test data available here: https://dvv.fi/en/reform-of-personal-identity-code
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels