Class SwiftUtil

Namespace
Subsembly.Swift
Assembly
Subsembly.Sepa.dll

Global utility methods.

public static class SwiftUtil
Inheritance
SwiftUtil
Inherited Members

Fields

MAXCREDITCARDNOLENGTH

The maximum length of a credit card number according to IsValidCreditCardNo(string).

public const int MAXCREDITCARDNOLENGTH = 16

Field Value

int

Remarks

Actually the official length range for payment card numbers is 8 through 19 digits. But in real life all credit card numbers are between 12 and 16 digits. Hence this constant has the value 16.

MINCREDITCARDNOLENGTH

The minimum length of a credit card number according to IsValidCreditCardNo(string).

public const int MINCREDITCARDNOLENGTH = 12

Field Value

int

Remarks

Actually the official length range for payment card numbers is 8 through 19 digits. But in real life all credit card numbers are between 12 and 16 digits. Hence this constant has the value 12.

Methods

AppendLuhn(string)

Computes and appends a Luhn check digit to the given string.

public static string AppendLuhn(string s)

Parameters

s string

Returns

string

Exceptions

ArgumentNullException

The parameter s was null.

CoalesceSpaces(string)

public static string CoalesceSpaces(string sText)

Parameters

sText string

Returns

string

ComputeLuhn(string, int)

Computes the Luhn check digit for the given string. The Luhn check is used, for example, with ISIN numbers and credit card numbers.

public static char ComputeLuhn(string s, int n)

Parameters

s string

The string to compute the Luhn check digit for. Must not be null.

n int

The number of characters to include in the check digit computation. Only the first n characters are used when computing the check digit. If this is zero, then the check digit for an empty string, i.e. '0', will be returned. Must not be negative.

Returns

char

The computed check digit, which is in the range from '0' to '9'.

Exceptions

ArgumentNullException

The parameter s was null.

ArgumentException

The parameter n was negative.

FormatException

The parameter s contains invalid characters.

IsValidCreditCardNo(string)

Fully validates the given credit card number

public static bool IsValidCreditCardNo(string sCreditCardNo)

Parameters

sCreditCardNo string

Returns

bool

If the given string looks like a valid credit card number, then true is returned. If the parameter was null, an empty string or an otherwise invalid credit card number, then false is returned.

Remarks

Verifies the length, the character set and the Luhn check digit of the given credit card number. It does not verify the validity of the leading digits, yet.

LuhnCheck(string)

Computes and checks the check digits from the given string according to the Luhn algorithm. The Luhn check is used, for example, with ISIN numbers and credit card numbers.

public static bool LuhnCheck(string s)

Parameters

s string

The string to check. If this is null or empty, then the result will be false.

Returns

bool

If the given string is correct accoring to the Luhn algorithm, then true is returned, otherwise false is returned.