Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Norwegian test numbers #10

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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