skwasjer / IbanNet

C# .NET IBAN validator, parser, builder and generator
Apache License 2.0
119 stars 31 forks source link

Senegal #36

Closed ayanesuarome closed 2 years ago

ayanesuarome commented 2 years ago

Why Senegal is not a supported country by this libraries? Can you include this country?

I tried to validate two valid IBANs from Senegal and the validator fails with message: "The country code is unknown/not supported."

IBANs: SN70C42354573538251454437598 SN08SN0100152000048500003035

Thanks.

skwasjer commented 2 years ago

Is planned for future release (v5), via opt-in of a new provider. Senegal is not officially listed in SWIFT and thus originally not implemented.

https://github.com/skwasjer/IbanNet/blob/develop/src/IbanNet/Registry/Wikipedia/WikipediaRegistryProvider.cs#L864-L870

A beta version is currently available on NuGet.

You must explicitly add the provider.

var validator = new IbanValidator(new IbanValidatorOptions
{
    Registry = new IbanRegistry
    {
        Providers =
        {
            new SwiftRegistryProvider(),
            new WikipediaRegistryProvider()
        }
    }
});
ayanesuarome commented 2 years ago

Thanks for the update.

skwasjer commented 2 years ago

Just noticed, looking at your 2nd example, it does not seem to conform (or rather Wikipedia is then wrong):

Pattern: 1a,23n

When ignoring country code and check digits SN0100152000048500003035 has two letters which the pattern does not allow (1a). This is why I don't like Wikipedia as a source :)

ayanesuarome commented 2 years ago

Ops, you are right. I need to search for a workaround for not supported countries. Thank you a lot for the time.

franacGIT commented 1 year ago

Hi Martijn.

Just to inform you. I've seen that you updated pattern for Senegal (2a,22n) but seems that it's failing with "unknow country code".
Can you confirm that this code SN08SN0100152000048500003035 is now valid? it is ok in IBAN checker in iban.com. Althoug maybe I'doing something wrong. This is my version Vb.Net

imagen

Thanks for your work!

Best Regards

skwasjer commented 1 year ago

@franacGIT you should not modify the validator options after creating the validator, because internally some references are passed along to other internal types, which will never see the 'new' options. In your example, the default registry is still used internally (instead of your custom configured one ) by the country code validator rule, evidenced by the different counts (81 vs 105).

Instead, first create and configure IbanValidatorOptions and then pass it to the constructor of the validator. Do not 'set' it via the property setter.

You can find a C# code snippet here which does just that. Let me know if you still have issues.

[edit] I never made the options immutable as it is also used in the IOptions<> pattern for dependency injection. Maybe I still should :)

franacGIT commented 1 year ago

Hi Martijn.

Solved! Passing to the constructor instead of assigning options did the trick. I found that snippet and tried to port it to vb...and almost did :). But It's not always obvious porting code from c# to vb.net. Here is the code, maybe it's useful form somebody else.

imagen

Many thanks for the kind, quick, and solvent answer!

Best regards