Skip to content

Commit

Permalink
Support for Norwegian test numbers, starting with 2 and 3
Browse files Browse the repository at this point in the history
These can be found at skatteetaten.no
  • Loading branch information
niklasmattsson authored and caspChristian committed Aug 23, 2024
1 parent 2e11931 commit 0768ca3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion VatValidation/Countries/NO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ namespace VatValidation.Countries;
/// valid, in: 977 074 010MVA, national: 977 074 010, vat: NO 977 074 010, stripped: 977074010, vatstripped: NO 977 074 010
/// valid, in: NO 977 074 010MVA, national: 977 074 010, vat: NO 977 074 010, stripped: 977074010, vatstripped: NO 977 074 010
/// valid, in: NO977074010, national: 977 074 010, vat: NO 977 074 010, stripped: 977074010, vatstripped: NO 977 074 010
/// valid, in: 310033243, national: 310 033 243, vat: NO 310 033 243, stripped: 310033243, comment: test number from skatteetaten.no
/// invalid, in: 310033242, national: 310033242, vat: NO 310033242, stripped: 310033242
/// valid, in: 212409472, national: 212 409 472, vat: NO 212 409 472, stripped: 212409472, comment: test number from skatteetaten.no
/// invalid, in: 212409471, national: 212409471, vat: NO 212409471, stripped: 212409471
/// </testcases>
public class NO : CountryBase
{
Expand All @@ -31,7 +35,9 @@ private NO() { }
private static readonly int[] _multipliers = [3, 2, 7, 6, 5, 4, 3, 2, 1];

// https://vatstack.com/articles/norway-vat-number-validation
private static bool ValidFormat(ReadOnlySpan<int> d) => d.Length == 9 && (d[0] == 8 || d[0] == 9);
private static bool ValidFormat(ReadOnlySpan<int> d) => d.Length == 9 && (
d[0] == 2 || d[0] == 3 ||
d[0] == 8 || d[0] == 9);
internal static bool Valid(ReadOnlySpan<int> digits) => ValidFormat(digits) && Valid(digits.ToArray());
private static bool Valid(int[] digits) =>
(11 - digits
Expand Down

0 comments on commit 0768ca3

Please sign in to comment.