chrsc/luhn-algorithm

Validate and create credit/bank/loyalty card numbers

1.0.0 2017-07-19 18:39 UTC

This package is auto-updated.

Last update: 2024-03-17 14:02:18 UTC


README

I created this as a utility class that will be used to validate card numbers, this works for credit card numbers, bank accounts, loyalty card numbers, and all other card numbers that follow the modulus 10 formula.

Other uses: Validate Canadian SIN / Greek SSN / Israel ID numbers, NPI numbers for American health care, IMEI numbers.

This could not have been created without Hans Peter Luhn's Algorithm.

Validate numbers

<?php
	$number = 123456;
	$luhn = new LuhnAlgorithm;
	if($luhn->validate($number)) {
		// number passes validation
	} else {
		// number does not pass validation
	}

Create numbers

<?php
	$luhn = new LuhnAlgorithm;
	$length = 16;
	$startswith = 4444;
	$cardnumber = $luhn->create($length, $startswith);
	// $cardnumber is now a valid card number that can be used or assigned