Struct SepaIBAN
Helper class for working with IBANs.
public struct SepaIBAN : IComparable<SepaIBAN>, IComparable
- Implements
- Inherited Members
Constructors
SepaIBAN(string)
Wrap an IBAN given in its electronic format with a new SepaIBAN instance.
public SepaIBAN(string sIBAN)
Parameters
sIBAN
stringComplete IBAN that shall be wrapped by the new SepaIBAN instance. The IBAN must be given in its electronic format, i.e. it must not contain whitespace or symbol characters, and all letters must be upper case. If this parameter is
null
or an empty string, then this will be a NullIBAN. Use Capture(string) in order to pre-process a user entered IBAN.
Remarks
This constructor does not validate the given IBAN checksum, but it validates whether the given string looks like an IBAN using IsValid(string).
Exceptions
- ArgumentException
The given IBAN string was no IBAN in its eletronic format (i.e. IsValid(string) returns
false
on it.
SepaIBAN(string, string, string)
Makes a new SepaIBAN by coercing the given parameters with a valid checksum.
public SepaIBAN(string sCountryCode, string sBankCode, string sAcctNo)
Parameters
sCountryCode
stringThe two letter country code of the country for which to generate the IBAN. This is not validated to be a real country code, and thus may be any string consisting of two upper case letters.
sBankCode
stringOptional bank code portion of the IBAN to be made, including any leading zeroes. May be
null
or an empty string.sAcctNo
stringThe complete account number portion of the IBAN to be made, including any leading zeroes. This must not be
null
and must not be an empty string.
Exceptions
- ArgumentNullException
The parameter sCountryCode or sAcctNo was
null
.- ArgumentException
The sCountryCode did not consist of two upper case characters, or, the sBankCode (if present) or sAcctNo did not consist solely of upper case characters and digits. Or the combined length did exceed the 34 character IBAN limit.
Fields
MAXLENGTH
The maximum length of any IBAN in electronic format without IBAN prefix and without any symbols or whitespace is 34.
public const int MAXLENGTH = 34
Field Value
MINLENGTH
The minimum length of any IBAN in electronic format without IBAN prefix and without any symbols or whitespace is 6.
public const int MINLENGTH = 6
Field Value
NullIBAN
Represents an unset SepaIBAN instance.
public static readonly SepaIBAN NullIBAN
Field Value
Properties
AcctNo
Provides the branch and account number part of this IBAN, less any leading zeroes.
public string AcctNo { get; }
Property Value
Remarks
May be null
, if it cannot be determined, because the IBAN structure is not
known.
BankCode
Provides the bank identification code part of this IBAN, less any leading zeroes.
public string BankCode { get; }
Property Value
Remarks
May be null
, if it cannot be determined, because the IBAN structure is not
known.
CountryCode
Provides the country code portion of this IBAN.
public string CountryCode { get; }
Property Value
IBAN
Provides the wrapped IBAN in its electronic format. The value is
null
if this IBAN IsNull.
public string IBAN { get; }
Property Value
IsNull
Indicates whether this IBAN is the NullIBAN.
public bool IsNull { get; }
Property Value
IsSepaCompliant
Indicates whether this IBAN belongs to a SEPA country and is not null.
public bool IsSepaCompliant { get; }
Property Value
Remarks
If this IsNull, then the value is false
.
Length
Returns the actual length of this IBAN. If this IsNull, then zero is returned.
public int Length { get; }
Property Value
Methods
Capture(string)
Creates the electronic format IBAN representation from a given paper format IBAN.
public static string Capture(string sPaperIBAN)
Parameters
sPaperIBAN
stringPaper format IBAN to be captured in electronic format. This may be prefixed with IBAN and may contain any number of blanks.
Returns
- string
Electronic format IBAN without blanks and without optional IBAN prefix. Any lower case characters have been converted to upper case. The result was not validated as an IBAN. It is up to the caller to validate the IBAN using IsValid(string) or other methods. The result may even be an empty string!
If the parameter sPaperIBAN was
null
or an empty string, then the return value will benull
.
Remarks
If the given paper IBAN starts with the prefix "IBAN", then this prefix is removed from the captured electronic IBAN.
Any non alphanumeric characters, such as whitespace or symbols, are removed from the captured electronic IBAN.
Any lower case letters are converted into upper case letters.
- See Also
CompareTo(SepaIBAN)
public int CompareTo(SepaIBAN aOtherIBAN)
Parameters
aOtherIBAN
SepaIBAN
Returns
CompareTo(object)
public int CompareTo(object aObject)
Parameters
aObject
object
Returns
Equals(object)
Compares the electronic IBAN representation for equivalence.
public override bool Equals(object obj)
Parameters
obj
objectRight hand side to compare to.
Returns
- bool
True if both are essentially the same IBAN.
Format()
Formats this electronic format IBAN into a paper format IBAN.
public string Format()
Returns
- string
Paper format IBAN. If this method is applied to the NullIBAN, then an empty string is returned.
Remarks
The paper representation of the IBAN is the same as the electronic format except that the IBAN is split up in groups of 4 characters separated by a space. The last group is variable in length, up to 4 characters.
Capture(string)Format(string)
Nicely formats the given IBAN input into groups of four IBAN characters.
public static string Format(string sIBAN)
Parameters
sIBAN
string
Returns
GetCountryCode(string)
Returns the country code portion of the given IBAN.
public static string GetCountryCode(string sIBAN)
Parameters
sIBAN
stringComplete IBAN to extract the country code from. The IBAN must be given in its electronic format, i.e. it must not contain whitespace or symbol characters, and all letters must be upper case. Use Capture(string) in order to pre-process a paper format IBAN. This parameter may be
null
.
Returns
- string
If the parameter was
null
, or an empty string, or an invalid IBAN, thennull
is returned. Otherwise the two letter country code is returned.
GetGermanAcctNo(string)
Extract the german account number from an IBAN.
public static string GetGermanAcctNo(string sIBAN)
Parameters
sIBAN
string
Returns
- string
The german account number for a valid german IBAN or
null
otherwise.
- See Also
GetGermanBankCode(string)
Extract the german bank code (Bankleitzahl) from an IBAN.
public static string GetGermanBankCode(string sIBAN)
Parameters
sIBAN
string
Returns
- string
The german bankcode for a valid german IBAN or
null
otherwise.
- See Also
GetHashCode()
Provides an hash code based on the electronic IBAN representation of this IBAN.
public override int GetHashCode()
Returns
- int
Hashcode.
IsValid(string)
Tests whether a string is a valid IBAN in its electronic format.
public static bool IsValid(string sIBAN)
Parameters
sIBAN
stringComplete IBAN to be checked. The IBAN must be given in its electronic format, i.e. it must not contain whitespace or symbol characters, and all letters must be upper case. This parameter must not be null. Use Capture(string) in order to pre-process a paper format IBAN.
Returns
- bool
If the given string is a valid IBAN, then
true
is returned. Otherwisefalse
is returned. If the parameter sIBAN wasnull
, thenfalse
is returned, too.
Remarks
The test first checks the string length (must be within MINLENGTH and MAXLENGTH), and whether the string consists solely of upper case alphanumeric characters. Then it checks whether the string starts with a two letter country code, followed by the two digits checksum. Also the checksum itself is verified. Finally it checks the length using all well known SepaIBANSpecs.
Capture(string)ToString()
Returns the electronic format of this IBAN.
public override string ToString()
Returns
- string
Electronic format of this IBAN.
TryCapture(string)
Tries to Capture(string) an IBAN. If no valid IBAN was captured, then NullIBAN is returned.
public static SepaIBAN TryCapture(string sPaperIBAN)
Parameters
sPaperIBAN
string
Returns
Operators
operator ==(SepaIBAN, SepaIBAN)
Equality operator compares the electronic format of the IBAN.
public static bool operator ==(SepaIBAN lhs, SepaIBAN rhs)
Parameters
Returns
operator !=(SepaIBAN, SepaIBAN)
Inequality operator compares the electronic format of the IBAN.
public static bool operator !=(SepaIBAN lhs, SepaIBAN rhs)