Class SwiftUtil
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
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
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
sstring
Returns
Exceptions
- ArgumentNullException
The parameter
swas null.
CoalesceSpaces(string)
public static string CoalesceSpaces(string sText)
Parameters
sTextstring
Returns
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
sstringThe string to compute the Luhn check digit for. Must not be
null.nintThe number of characters to include in the check digit computation. Only the first
ncharacters 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
swas null.- ArgumentException
The parameter
nwas negative.- FormatException
The parameter
scontains invalid characters.
IsValidCreditCardNo(string)
Fully validates the given credit card number
public static bool IsValidCreditCardNo(string sCreditCardNo)
Parameters
sCreditCardNostring
Returns
- bool
If the given string looks like a valid credit card number, then
trueis returned. If the parameter wasnull, an empty string or an otherwise invalid credit card number, thenfalseis 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
sstringThe 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
trueis returned, otherwisefalseis returned.