Class SepaUtil

Namespace
Subsembly.Sepa
Assembly
Subsembly.Sepa.dll

Collection of useful constants and static utility methods for processing SEPA data.

public static class SepaUtil
Inheritance
SepaUtil
Inherited Members

Fields

MaxIdLen

The maximum length of a SEPA identification. (35)

public const int MaxIdLen = 35

Field Value

int

MaxNmLen

The maximum length of a party name in SEPA messages. (70)

public const int MaxNmLen = 70

Field Value

int

MaxRmtInfLen

The maximum length of an unstructured remittance information string. (140)

public const int MaxRmtInfLen = 140

Field Value

int

NONREF

String constant containing "NONREF".

public const string NONREF = "NONREF"

Field Value

string

NOTPROVIDED

String constant containing "NOTPROVIDED".

public const string NOTPROVIDED = "NOTPROVIDED"

Field Value

string

SMNDA

String constant "SMNDA".

public const string SMNDA = "SMNDA"

Field Value

string

StructuredCommunicationReference

String constant StructuredCommunicationReference ("SCOR")

public const string StructuredCommunicationReference = "SCOR"

Field Value

string

UNBEKANNT

String constant containing "UNBEKANNT".

public const string UNBEKANNT = "UNBEKANNT"

Field Value

string

UNKNOWN

String constant containing "UNKNOWN".

public const string UNKNOWN = "UNKNOWN"

Field Value

string

Methods

BuildID(string, string)

Builds an ID with country code and MOD-97-10 check digits.

public static string BuildID(string sCountryCode, string sReference)

Parameters

sCountryCode string

Two upper case characters representing the country code that is included as the first two characters of the ID.

sReference string

A string of digits and upper case characters that represents the actual reference value that is included after the two check digits.

Returns

string

An ID in the format "XX00REFERENCE", where "XX" is the country code, "00" are two MOD-97-10 check digits and "REFERENCE" is the given reference value.

Exceptions

ArgumentNullException

A parameter was null.

ArgumentException

The country code parameter did not consist of two upper case characters.

CaptureAlphaNum(string)

Captures digits and alpha characters from a given string. Converting lower case to upper case and skipping white space.

public static string CaptureAlphaNum(string s)

Parameters

s string

Returns

string

CheckCharset(char)

Checks whether the given character is an allowed SEPA character.

public static bool CheckCharset(char ch)

Parameters

ch char

The character to be checked.

Returns

bool

If the given character is a valid SEPA character, then true is returned. Otherwise false is returned.

Remarks

Banks must be able to support the Latin character set commonly used in international communication, as follows:

a b c d e f g h i j k l m n o p q r s t u v w x y z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
0 1 2 3 4 5 6 7 8 9
/ - ? : ( ) . , ' +
Space

CheckCharset(string)

Checks whether the given string contains only allowed SEPA characters.

public static bool CheckCharset(string sText)

Parameters

sText string

The string to be checked. This could be a Name, or a RemittanceInformation or any SEPA identification.

Returns

bool

If the given text contains only valid characters, then true is returned. If any invalid character is found, then false is returned.

See Also

CheckGermanCharset(char)

Checks whether the given character is an allowed SEPA character according to the German DK rules.

public static bool CheckGermanCharset(char ch)

Parameters

ch char

The character to be checked.

Returns

bool

If the given character is an allowed SEPA character, then true is returned. Otherwise false is returned.

Remarks

a b c d e f g h i j k l m n o p q r s t u v w x y z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
0 1 2 3 4 5 6 7 8 9
/ - ? : ( ) . , ' +
Ä Ö Ü ä ö ü ß & * $ %
Space

CheckGermanCharset(string)

Checks whether the given string contains only SEPA characters allowed in the German DK SEPA specification.

public static bool CheckGermanCharset(string sText)

Parameters

sText string

The string to be checked. This could be a Name, or a RemittanceInformation or any SEPA identification.

Returns

bool

If the given text contains only valid characters, then true is returned. If any invalid character is found, then false is returned.

See Also

CheckIdentification(string)

public static bool CheckIdentification(string sIdentification)

Parameters

sIdentification string

The identification value to check. Must not be null. An empty string is not considered to be a valid identification.

Returns

bool

If the given sIdentification is a valid identification value, then true is returned. Otherwise false is returned.

Remarks

In addition to length and character set, this also checks that the identification does not start with a slash "/", end with a slash "/", or contain a double slash "//".

Exceptions

ArgumentNullException

CheckTagName(string)

Checks whether the given string contains only valid XML tag name characters.

public static bool CheckTagName(string sTagName)

Parameters

sTagName string

The XML tag name to be checked.

Returns

bool

If the given tag name contains only valid tag name characters, then true is returned. If any invalid character is found, then false is returned.

Exceptions

ArgumentNullException

The parameter was null.

ArgumentException

The parameter was an empty string.

DecimalPlaces(decimal)

Computes the numer of significant decimal places in a decimal amount.

public static int DecimalPlaces(decimal d)

Parameters

d decimal

Returns

int

Exceptions

ArgumentOutOfRangeException

The parameter d was a negative value.

EnforceCharset(string, char)

Creates a valid SEPA string from any string.

public static string EnforceCharset(string sText, char chSubstituteChar = '.')

Parameters

sText string

The text which shall be converted to a string that contains only valid SEPA characters. If this is null, then the return value is null, too.

chSubstituteChar char

The character that will be used to replace any invalid characters that do not have a special replacement character in the input string. This parameter is defaulted to a full stop '.'.

Returns

string

A valid SEPA string made from the input string where all invalid characters have been replaced by the substitute character.

Remarks

This method replaces the German umlaut characters 'ÄÖÜäöüß' with their non-decorated base characters 'AOUaous'. The ampersand '&' is replaced by a plus '+'. All other invalid characters are replaced by the given substitution character.

Exceptions

ArgumentException

The given substitute character was itself not a valid SEPA character.

EnforceGermanCharset(string, char)

Creates a valid SEPA string from any string according to the German DK SEPA specification.

public static string EnforceGermanCharset(string sText, char chSubstituteChar = '.')

Parameters

sText string

The text which shall be converted to a string that contains only valid SEPA characters. If this is null, then the return value is null, too.

chSubstituteChar char

The character that will be used to replace any invalid characters that do not have a special replacement character in the input string. This parameter is defaulted to a full stop '.'.

Returns

string

A valid SEPA string made from the input string where all invalid characters have been replaced by the substitute character.

Exceptions

ArgumentException

The given substitute character was itself not a valid SEPA character.

EnforceGermanName(string)

Enforces a valid SEPA name from a given string according to the German DK SEPA specification.

public static string EnforceGermanName(string sName)

Parameters

sName string

Returns

string

A valid SEPA name string derived from the given name parameter. If the parameter was null or an empty string, then the string constant UNBEKANNT will be returned.

Remarks

If the given name is longer than MaxNmLen characters, it will be truncated. The string is then passed to EnforceGermanCharset(string, char) in order to enforce a valid character set. The resulting string is returned.

EnforceIdentification(string)

Enforces a valid SEPA identification from a given string.

public static string EnforceIdentification(string sIdentification)

Parameters

sIdentification string

The identification string to process. This may be null, or an empty string.

Returns

string

A valid SEPA identification string derived from the given sIdentification parameter. If the parameter was null or an empty string, or consists solely of whitespace, then the string constant NOTPROVIDED will be returned.

Remarks

If the given string is longer than MaxIdLen characters, it will be truncated. The string is then passed to EnforceCharset(string, char) in order to enforce a valid character set. The resulting string is returned.

Note that a valid MandateIdentification must not contain blank characters in addition to the enforcement done here!

EnforceIdentification(string, string)

Enforces a valid SEPA identification from a given string.

public static string EnforceIdentification(string sIdentification, string sDefault)

Parameters

sIdentification string

The identification string to process. This may be null, or an empty string.

sDefault string

The default string to return in case the sIdentification is null, empty, or consists solely of whitespace.

Returns

string

EnforceName(string)

Enforces a valid SEPA name from a given string.

public static string EnforceName(string sName)

Parameters

sName string

Returns

string

A valid SEPA name string derived from the given name parameter. If the parameter was null or an empty string, then the string constant UNKNOWN will be returned.

Remarks

If the given name is longer than MaxNmLen characters, it will be truncated. The string is then passed to EnforceCharset(string, char) in order to enforce a valid character set. The resulting string is returned.

EnforceName(string, string)

public static string EnforceName(string sName, string sDefault)

Parameters

sName string
sDefault string

Returns

string

GenerateIdentification(string)

Generates a new and unique SEPA identification.

public static string GenerateIdentification(string sPrefix)

Parameters

sPrefix string

Optional prefix that will be included in the generated identification. If given, it must be shorter than MaxIdLen.

Returns

string

Generates an unique numeric character identification based on the current time. The returned string can be used as a unique SEPA identifier.

Exceptions

ArgumentException

The given prefix was too long.

GetAllSepaCountryCodes()

Returns a sorted array of all country codes of all countries that belong to the SEPA payments area.

public static string[] GetAllSepaCountryCodes()

Returns

string[]

GetCurrencyDecimals(string)

Returns the number of decimal places of a particular currency.

public static int GetCurrencyDecimals(string sCcy)

Parameters

sCcy string

ISO currency code of the requested currency. If this is null, empty or an invalid or unknown currency code, then the default value 2 is returned.

Returns

int

Number of decimals of the requested currency. Currently either 0, 2, or 3.

Remarks

Known currencies may have zero, two, or three decimals. If an unknown currency is requested, then the default value two is returned. This method never throws an exception.

IsAlpha(char)

Indicates whether the given character is an upper case letter.

public static bool IsAlpha(char ch)

Parameters

ch char

Character to test.

Returns

bool

True if the character is an upper case letter in the range from 'A' through 'Z'.

IsAlpha(string)

Tests whether the entire string contains only upper case letters.

public static bool IsAlpha(string s)

Parameters

s string

The string to test.

Returns

bool

True if all characters are upper case letters in the range from 'A' through 'Z'.

Exceptions

ArgumentNullException

The parameter was null.

IsAlphaNumeric(char)

Indicates whether the given character is a digit or an upper case letter.

public static bool IsAlphaNumeric(char ch)

Parameters

ch char

Character to test.

Returns

bool

True if the character is an upper case letter in the range from 'A' through 'Z' or a digit in the range from '0' through '9'.

IsAlphaNumeric(string)

Tests whether the entire string contains only digits or upper case letters.

public static bool IsAlphaNumeric(string s)

Parameters

s string

The string to test.

Returns

bool

True if all characters are upper case letters in the range from 'A' through 'Z' or digits in the range from '0' through '9'.

Exceptions

ArgumentNullException

The parameter was null.

IsAlphaNumeric(string, int)

Tests whether the entire string contains digits or upper case letters.

public static bool IsAlphaNumeric(string s, int nLength)

Parameters

s string

The string to test. If s is null, then false is returned.

nLength int

The required length of the string to test. This must be one or larger.

Returns

bool

True if, and only if, the length of s matches nLength and all characters are upper case letters in the range from 'A' through 'Z' or digits in the range from '0' through '9'.

IsEuCountryCode(string)

Determines whether the given country code is a valid EU member country code.

public static bool IsEuCountryCode(string sCountryCode)

Parameters

sCountryCode string

Returns

bool

If the parameter sCountryCode is null, or an invalid country code, or not a country code of a country that is an EU member, then false is returned. Otherwise true is returned.

See Also

IsLatin1(char)

Indicates whether the given character is a printable character from the Latin 1 (ISO 8859-1) character set.

public static bool IsLatin1(char ch)

Parameters

ch char

Character to test.

Returns

bool

True if the character is a printable latin 1 character in the range from '\u0020' through '\u007E' or in the range from '\u00A0' through '\u00FF'.

IsLatin1(string)

Tests whether the entire string contains only printable characters from the Latin 1 (ISO 8859-1) character set.

public static bool IsLatin1(string s)

Parameters

s string

The string to test.

Returns

bool

True if all characters are printable latin 1 characters in the range from '\u0020' through '\u007E' or in the range from '\u00A0' through '\u00FF'.

Exceptions

ArgumentNullException

The parameter was null.

IsNumeric(char)

Indicates whether the given character is a digit.

public static bool IsNumeric(char ch)

Parameters

ch char

Character to test.

Returns

bool

True if the character is a digit in the range from '0' through '9'.

IsNumeric(string)

Tests whether the entire string contains digits only.

public static bool IsNumeric(string s)

Parameters

s string

The string to test.

Returns

bool

True if all characters are digits in the range from '0' through '9'.

Exceptions

ArgumentNullException

The parameter was null.

IsSepaCountryCode(string)

Determines whether the given country code is a valid country code of a SEPA country.

public static bool IsSepaCountryCode(string sCountryCode)

Parameters

sCountryCode string

Returns

bool

If the parameter sCountryCode is null, or an invalid country code, or not a country code of a country that belongs to SEPA, then false is returned. Otherwise true is returned.

See Also

IsValidCountryCode(string)

Checks the syntax of the given country code.

public static bool IsValidCountryCode(string sCountryCode)

Parameters

sCountryCode string

Returns

bool

Remarks

This only validates the syntax and does not check whether the given country actually exists. A valid country code consists of exactly two upper case letters (A-Z).

IsValidCurrencyCode(string)

Checks the syntax of the given currency code.

public static bool IsValidCurrencyCode(string sCurrencyCode)

Parameters

sCurrencyCode string

Returns

bool

Remarks

This only validates the syntax and does not check whether the given currency actually exists. A valid currency code consists of exactly three upper case letters (A-Z).

IsValidID(string)

Validates an ID including a MOD-97-10 validation.

public static bool IsValidID(string sID)

Parameters

sID string

The ID to validate. This could be an IBAN, a creditor reference or a creditor ID, or any other ID that follows the same basic pattern.

Returns

bool

If the given ID is valid, then true is returned. Otherwise false is returned.

Remarks

The validation checks whether the first two characters are upper case letters, and the subsequent two characters are valid MOD-97-10 check digits. The remainder must consist of digits and upper case letters, only.

NullTrim(string)

Trims whitespace from a string, returning null, when the trimmed string is empty.

public static string NullTrim(string s)

Parameters

s string

String to be trimmed. May be null.

Returns

string

Trim(string)

Trims whitespace from a string.

public static string Trim(string s)

Parameters

s string

String to be trimmed. May be null.

Returns

string

If the parameter s was null, then null is returned, otherwise the trimmed string is returned. If the given string consists solely of whitespace, then an empty string will be returned.

Trim(string, int)

Trims whitespace from a string and truncates to MaxLen.

public static string Trim(string s, int nMaxLen)

Parameters

s string

String to be trimmed. May be null.

nMaxLen int

Max length of returned string.

Returns

string

If the parameter s was null, then null is returned, otherwise the trimmed and truncated string is returned. The length of the returned string will be smaller or equal to MaxLen. If the given string consists solely of whitespace, then an empty string will be returned.

TrimReference(string)

Trims the given string using NullTrim(string). If the result is NONREF, or NOTPROVIDED, then null is returned. Otherwise the trimmed string is returned.

public static string TrimReference(string s)

Parameters

s string

String to be trimmed. May be null.

Returns

string

Returns the trimmed string, or null.