anghelvalentin / CountryValidator

C# Validations for Social Security Numbers, VAT Codes and tax identification numbers
https://randommer.io/SocialNumber/VatValidator
36 stars 20 forks source link

Update NorwayValidator : TIN ending with 00 #11

Closed LordSuprachris closed 1 month ago

LordSuprachris commented 2 years ago

Hi

Some Norwegian Tax Identification Number are marked as invalid even if they are valid. This happens when the number ends with "00". Example : 14087726100 is a valid Norwegian TIN number If I apply CalculateChecksum for the first nine digits, I have : 3 + 28 + 0 + 8 + 56 + 63 + 8 + 30 + 2 ==> sum = 198 sum % 11 = 0 (198/11 = 18, mod = 0) Then, the function returns 11, which is obviously different from 0. By adding another % 11 operation, it solves the problem. If the result of sum % 11 is less than 0, nothing changes. If the result is 11, it will return 11 % 11 => 0.

It works also for the second checksum :
the digits multiplied by the weights are 5 + 16 + 0 + 16 + 49 + 42 + 10 + 24 + 3 + 0 ==> sum = 165 sum % 11 = 0 (165/11 = 15, mod = 0)