Skip to content
skwas edited this page Dec 11, 2019 · 14 revisions

Use the IbanValidator for full control over the validation.

The benefit of using the validator is that it implements the IIbanValidator interface and can thus be easily mocked. Additionally, the ValidationResult provides extra context, like the matched country (if any).

Example

IIbanValidator validator = new IbanValidator();
ValidationResult validationResult = validator.Validate("NL91ABNA041716430");
if (validationResult.IsValid)
{
    // For example:
    if (validationResult.Country.TwoLetterISORegionName != "NL")
    {
        throw new InvalidOperationException("Please provide a Dutch bank account.");
    }
}
else
{
    Console.WriteLine(validationResult.Error.ErrorMessage);
}