LUHN_CHECK()

All functions > STRING > LUHN_CHECK()

Returns TRUE if a string passes the Luhn algorithm (modulus 10 checksum).

Signatures

Returns: TRUE if the string passes the Luhn check, FALSE otherwise

LUHN_CHECK(string: VARCHAR) → BOOLEAN
sql
ParameterTypeRequiredDescription
stringVARCHARYesString of digits to validate

Notes

  • Commonly used for validating credit card numbers
  • Non-digit characters (spaces, hyphens) are typically ignored
  • Also known as mod 10 algorithm
  • Returns FALSE for invalid input

Examples

FeatureQL
SELECT
    -- Valid Visa card number
    f1 := LUHN_CHECK('4532015112830366'),
    -- Valid Discover card
    f2 := LUHN_CHECK('6011514433546201'),
    -- Invalid card number
    f3 := LUHN_CHECK('1234567890123456'),
    -- Valid Luhn number
    f4 := LUHN_CHECK('79927398713'),
    -- Invalid Luhn number
    f5 := LUHN_CHECK('79927398710'),
    -- Valid with separators
    f6 := LUHN_CHECK('4532-0151-1283-0366')
;
Result
f1 BOOLEANf2 BOOLEANf3 BOOLEANf4 BOOLEANf5 BOOLEANf6 BOOLEAN
truetruefalsetruefalsetrue

Last update at: 2026/06/20 10:08:10