DEV Community

sfyan belhaj
sfyan belhaj

Posted on

How to Validation Credit Card PHP Laravel ??

How to Validation Credit Card PHP Laravel ??

Image description

there is a question in mind for some Developers How do some Websites check the type of Credit Card and then Submit it to the API Visa or Master Card, etc. … How is this Working?

I will today offer a library in Laravel to Provide the Solution in just 2 lines of Code !! 

https://github.com/sfyanbel/CreditCardValidation 
How to install it in your Laravel Project?
composer require sfyanbel/credit-card-validation

 How to use

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use sfyanbel\CreditCardValidation\CreditCard;

class TestController extends Controller
{

    function test(){

        $ob = new CreditCard();
        return $ob->getTypeCreditCard("43943418067844");

    }

}
Enter fullscreen mode Exit fullscreen mode

in This Example, we use this Card "43943418067844" and this will return the Following ['Visa',2]
first index name of the Card
second index id of the Card
and for other Card, you will find this

['AmericanExpress',1] , ['Visa',2] , ['MasterCards',3] , ['Discover',4]
Enter fullscreen mode Exit fullscreen mode

and for other numbers not Defined

['String incorrect'];
Enter fullscreen mode Exit fullscreen mode

This is in case the length of the card numbers is incorrect

['The count of digits is incorrect'];
Enter fullscreen mode Exit fullscreen mode

Top comments (0)