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

Last update at: 2026/03/03 16:47:38
Last updated: 2026-03-03 16:48:19