Class SepaUtil
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
MaxNmLen
The maximum length of a party name in SEPA messages. (70)
public const int MaxNmLen = 70
Field Value
MaxRmtInfLen
The maximum length of an unstructured remittance information string. (140)
public const int MaxRmtInfLen = 140
Field Value
NONREF
String constant containing "NONREF".
public const string NONREF = "NONREF"
Field Value
NOTPROVIDED
String constant containing "NOTPROVIDED".
public const string NOTPROVIDED = "NOTPROVIDED"
Field Value
SMNDA
String constant "SMNDA".
public const string SMNDA = "SMNDA"
Field Value
StructuredCommunicationReference
String constant StructuredCommunicationReference ("SCOR")
public const string StructuredCommunicationReference = "SCOR"
Field Value
UNBEKANNT
String constant containing "UNBEKANNT".
public const string UNBEKANNT = "UNBEKANNT"
Field Value
UNKNOWN
String constant containing "UNKNOWN".
public const string UNKNOWN = "UNKNOWN"
Field Value
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
sCountryCodestringTwo upper case characters representing the country code that is included as the first two characters of the ID.
sReferencestringA 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
sstring
Returns
CheckCharset(char)
Checks whether the given character is an allowed SEPA character.
public static bool CheckCharset(char ch)
Parameters
chcharThe character to be checked.
Returns
- bool
If the given character is a valid SEPA character, then
trueis returned. Otherwisefalseis 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
sTextstringThe 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
trueis returned. If any invalid character is found, thenfalseis 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
chcharThe character to be checked.
Returns
- bool
If the given character is an allowed SEPA character, then
trueis returned. Otherwisefalseis 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
sTextstringThe 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
trueis returned. If any invalid character is found, thenfalseis returned.
- See Also
CheckIdentification(string)
public static bool CheckIdentification(string sIdentification)
Parameters
sIdentificationstringThe identification value to check. Must not be
null. An empty string is not considered to be a valid identification.
Returns
- bool
If the given
sIdentificationis a valid identification value, thentrueis returned. Otherwisefalseis 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
CheckTagName(string)
Checks whether the given string contains only valid XML tag name characters.
public static bool CheckTagName(string sTagName)
Parameters
sTagNamestringThe XML tag name to be checked.
Returns
- bool
If the given tag name contains only valid tag name characters, then
trueis returned. If any invalid character is found, thenfalseis 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
ddecimal
Returns
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
sTextstringThe text which shall be converted to a string that contains only valid SEPA characters. If this is
null, then the return value isnull, too.chSubstituteCharcharThe 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
sTextstringThe text which shall be converted to a string that contains only valid SEPA characters. If this is
null, then the return value isnull, too.chSubstituteCharcharThe 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
sNamestring
Returns
- string
A valid SEPA name string derived from the given name parameter. If the parameter was
nullor 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
sIdentificationstringThe identification string to process. This may be
null, or an empty string.
Returns
- string
A valid SEPA identification string derived from the given
sIdentificationparameter. If the parameter wasnullor 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
sIdentificationstringThe identification string to process. This may be
null, or an empty string.sDefaultstringThe default string to return in case the
sIdentificationisnull, empty, or consists solely of whitespace.
Returns
EnforceName(string)
Enforces a valid SEPA name from a given string.
public static string EnforceName(string sName)
Parameters
sNamestring
Returns
- string
A valid SEPA name string derived from the given name parameter. If the parameter was
nullor 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
Returns
GenerateIdentification(string)
Generates a new and unique SEPA identification.
public static string GenerateIdentification(string sPrefix)
Parameters
sPrefixstringOptional 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
sCcystringISO 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
chcharCharacter to test.
Returns
- bool
Trueif 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
sstringThe string to test.
Returns
- bool
Trueif 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
chcharCharacter to test.
Returns
- bool
Trueif 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
sstringThe string to test.
Returns
- bool
Trueif 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
sstringThe string to test. If
sisnull, thenfalseis returned.nLengthintThe required length of the string to test. This must be one or larger.
Returns
- bool
Trueif, and only if, the length ofsmatchesnLengthand 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
sCountryCodestring
Returns
- bool
If the parameter
sCountryCodeisnull, or an invalid country code, or not a country code of a country that is an EU member, thenfalseis returned. Otherwisetrueis 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
chcharCharacter to test.
Returns
- bool
Trueif 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
sstringThe string to test.
Returns
- bool
Trueif 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
chcharCharacter to test.
Returns
- bool
Trueif 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
sstringThe string to test.
Returns
- bool
Trueif 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
sCountryCodestring
Returns
- bool
If the parameter
sCountryCodeisnull, or an invalid country code, or not a country code of a country that belongs to SEPA, thenfalseis returned. Otherwisetrueis returned.
- See Also
IsValidCountryCode(string)
Checks the syntax of the given country code.
public static bool IsValidCountryCode(string sCountryCode)
Parameters
sCountryCodestring
Returns
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
sCurrencyCodestring
Returns
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
sIDstringThe 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
trueis returned. Otherwisefalseis 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
sstringString to be trimmed. May be
null.
Returns
Trim(string)
Trims whitespace from a string.
public static string Trim(string s)
Parameters
sstringString to be trimmed. May be
null.
Returns
- string
If the parameter
swasnull, thennullis 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
Returns
- string
If the parameter s was
null, thennullis 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
sstringString to be trimmed. May be
null.
Returns
- string
Returns the trimmed string, or
null.