luhn_check
function
Applies to: Databricks SQL Databricks Runtime 13.3 LTS 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