luhn_check function

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime 13.0 and above

Returns true if numStr passes the Luhn algorithm check.

The Luhn algorithm is used for example, to validate creditcard numbers.

Syntax

luhn_check(numStr)

Arguments

  • numStr: An STRING expression composed of digits '0' through '9'.

Returns

A BOOLEAN.

If numStr contains any character that is not a digit the result is false. If the input’s last digit matches the algorithm the result is true

Examples

> SELECT luhn_check('12345');
 false

> SELECT luhn_check('12344');
 true

> SELECT luhn_check('1234 4');
 false