IsValidLuhn

Learn about the IsValidLuhn OTTL converter function.

The IsValidLuhn converter validates if a string passes the Luhn algorithm check. This is commonly used for validating credit card numbers, IMEI numbers, and other identification numbers.

Syntax: IsValidLuhn(value)

  • value: the string to validate using the Luhn algorithm

Input

{
	"_type": "log",
	"body": "Payment processing",
	"resource": {...},
	"attributes": {
		"card_number": "4532015112830366",
		"invalid_card": "1234567890123456"
	}
}

Statement

set(attributes["valid_card"], IsValidLuhn(attributes["card_number"]))
set(attributes["invalid_check"], IsValidLuhn(attributes["invalid_card"]))

Output

{
	"_type": "log",
	"body": "Payment processing",
	"resource": {...},
	"attributes": {
		"card_number": "4532015112830366",
		"invalid_card": "1234567890123456",
		"valid_card": true,
		"invalid_check": false
	}
}

The Luhn algorithm correctly validated the first card number and identified the second as invalid.