Spectrum.Ird 2.2.2

dotnet add package Spectrum.Ird --version 2.2.2
NuGet\Install-Package Spectrum.Ird -Version 2.2.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Spectrum.Ird" Version="2.2.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Spectrum.Ird --version 2.2.2
#r "nuget: Spectrum.Ird, 2.2.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Spectrum.Ird as a Cake Addin
#addin nuget:?package=Spectrum.Ird&version=2.2.2

// Install Spectrum.Ird as a Cake Tool
#tool nuget:?package=Spectrum.Ird&version=2.2.2

Azure DevOps builds Azure DevOps builds License: MIT NuGet Badge

New Zealand IRD Number and Bank Account Number Validation

This is a library to validate IRD numbers and New Zealand bank account numbers according to the "Resident Withholding Tax (RWT) and Non-Resident Withholding Tax (NRWT)" specification published by the New Zealand Inland Revenue Department (IRD).

The specification used in this implementation is here.

Installation

This library is distributed with Nuget. The package can be installed by:

Install-Package Spectrum.Ird

Usage

Import the namespace.

using Spectrum.Ird;

Quick Start

To validate an IRD number:

var isValid = 49091850.IsValidIrdNumber();

To validate a New Zealand bank account number:

var isValid = "01-0902-0068389-00".IsValidNZBankAccount();

IRD Number

Validation

Create an instance of the IrdNumber class with an IRD Number expressed as a long data type. Call the IsValid() method to validate it.

var irdNumber = new IrdNumber(49091850);
var result = irdNumber.IsValid();

Friendly Display

After an IRD number has been instantiated, the ToString() method can be called to get a friendly display of the IRD number, hyphen separated.

// arrange
var irdNumber = new IrdNumber(49091850);

// act
var result = irdNumber.ToString();

// assert
Assert.AreEqual("49-091-850", result);

Static Validation

A static method of validation is available.

var isValid = IrdNumber.IsValid(49091850);

Bank Account

Validation

Create an instance of the NZBankAccount with a bank account number in its constituent parts. That is, its bank, branch, account base and suffix. Call the IsValid() method to validate it.

var bank = 1;
var branch = 902;
var accountBase = 68389;
var suffix = 0;

var account = new NZBankAccount(bank, branch, accountBase, suffix);
var isValid = account.IsValid();

Parsing

An instance can also be created by parsing a string value in the format XX-XXXX-XXXXXXX-XX(X) where X is a digit and the suffix can be either 2 or 3 digits. Hyphens, spaces or periods can be used as separators. If the value cannot be parsed, a FormatException is thrown.

Parsing an account number does not validate it. Once an instance has been created, it can then be validated.

try
{
    var account = NZBankAccount.Parse("01-0902-0068389-00");
    var isValid = account.IsValid();
}
catch (FormatException ex)
{
    // handle exception
}

A TryParse() method is also available.

if (NZBankAccount.TryParse("01-0902-0068389-00", out NZBankAccount account))
{
    var isValid = account.IsValid();
}

Friendly Display

After an account number has been instantiated, the ToString() method can be called to get a friendly display of the account number, hyphen separated.

// arrange
var account = new NZBankAccount(1, 902, 68389, 0);

// act
var result = account.ToString();

// assert
Assert.AreEqual("01-0902-0068389-00", result);

Static Validation

A static method of validation is available.

var isValid = NZBankAccount.IsValid(1, 902, 68389, 0);

Acknowledgements

Release Notes

2.2.2

2020-10-21

  • Override ToString() to output a human-friendly formatted IRD number.
2.2.1

2020-10-04

  • Added exception XML documentation for the Parse method.
  • Added ExpectedExceptionWithMessage for unit testing.
2.2.0

2020-09-27

  • Aligned how the Parse method works with typical Microsoft parsing methods such as Int32.Parse(string). An exception will now be thrown if the value cannot be parsed instead of returning null.
  • Added extension methods.
2.1.0

2020-09-26

  • Added IRD Number validation.
  • Refactored NZBankAccount to use integer arrays.
  • Removed Algorithm and Modulus as these were never populated.
2.0.0

2020-09-21

  • Changed the namespace from Spectrum.IrdValidation to Spectrum.Ird.
  • Renamed NZBankAccountValidator to NZBankAccount.
  • Removed AccountNumber property as it is misleading and could be confused with ToString(). This is used privately as part of the validation algorithm.
  • Added Parse() to accept bank account numbers in a "XX-XXXX-XXXXXXX-XX(X)" format.
1.0.2

2020-09-17

  • Override ToString() to output a human-friendly formatted account number.
1.0.1

2020-09-12

  • Added XML documentation.
1.0.0

2020-09-06

  • Initial release
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.2.2 18,918 10/21/2020
2.2.1 814 10/4/2020
2.2.0 948 9/27/2020
2.1.0 1,011 9/26/2020
2.0.0 790 9/21/2020