PHPackages                             neblar/descardid - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. neblar/descardid

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

neblar/descardid
================

DesCardId (of Card Identification) is a php library used for identifying credit card numbers in text.

06PHP

Since Dec 27Pushed 8y ago1 watchersCompare

[ Source](https://github.com/neblar/DesCardId_PHP)[ Packagist](https://packagist.org/packages/neblar/descardid)[ RSS](/packages/neblar-descardid/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (1)Used By (0)

DesCardId\_PHP
==============

[](#descardid_php)

DesCardId (of Card Identification) is an open source library written in JavaScript and PHP that can be used to identify credit card numbers in any given text with certain degree of probability.

How it works
------------

[](#how-it-works)

The library follows the following process to identify credit card numbers in a given text:

1. Identify fragments of text which have numbers in them. These are fragments without alphabets but may contain other characters for example spaces, dashes etc. The idea here is that if people write down a credit card number they would generally not include alphabets in between the number unless they are deliberately trying to bypass checks. For example, "Lorem ipsum 123 456 foo bar", would result in extraction of the fragment " 123 456 ", while "Lorem 123 ipsum 456 foo 789 bar" would result in extraction of " 123 ", " 456 ", " 789 " as separate fragments.
2. These fragments are then stripped of all special characters, leaving behind only the number that they contain. For example, a fragment like "1234 - - 567 .. 89" would then be converted into "123456789".
3. This number is then tested to check if it could be a credit card or not, this follows a separate sub process outlined here:
    1. Check if the number can possibly be a credit card number. This check is used to weed out numbers that are too short or too long to be credit card numbers, and check for any other basic characteristics which a credit card number must absolutely have.
    2. Calculate the probability of the number actually being a credit card number. This involves performing a check sum aka LUHN check, a validation based on length to match with popular card lengths, trying to match the number with a popular card provider and matching the number to known set of test numbers.
    3. The total probability assigned to a number is then compared with a threshold, if the probability is over the threshold then we are sure that it is a credit card number otherwise we are not.

Examples
--------

[](#examples)

Upon use of the main class's (CardIdentifier) inspectText function we get the following results:

**Provided text** `foo 5555555555554444 bla bla`

**Resulting text** `foo {{5555555555554444}[ALERT]} bla bla`

[**Interactive example**](http://neblar.com/softwareDevelopment/desCardId/desCardId_php)

How to Use
----------

[](#how-to-use)

1. Include the library either by any of the following methods:

    - **Composer dependency**

        You can include the library as a composer dependency and then use it as follows:

        ```
            use Neblar\DesCardId\CardIdentifier;
            ...
            $identifier = new CardIdentifier(85);
            $renderText = $identifier->inspectTextWithNotices($testText);
            }
        ```
    - **Manual includes**

        If your project does not make use of composer you can manually include the folder `src` and the file `DesCardId.php` in your project and use the library as follows:

        ```
            use Neblar\DesCardId\CardIdentifier;
            require_once('assets/php/DesCardId.php');
            ...
            $identifier = new CardIdentifier(85);
            $renderText = $identifier->inspectTextWithNotices($testText);
            }
        ```
2. Initialize an object of the `CardIdentifier` class as

    ```
       $identifier = new CardIdentifier();
    ```
3. Pass the text you want to inspect to function `inspectText` of this object as

    ```
       $inspectedText = $identifier.inspectText("foo bar");
    ```

Customization
-------------

[](#customization)

The library has room for customization at different stages. Here are some of the common customizations that you can perform:

### Changing the markers for Alert and Notice

[](#changing-the-markers-for-alert-and-notice)

You can change the marker that is used to identify the numbers by passing the desired text to the constructor of `CardIdentifier` by

```
    $identifier = new CardIdentifier(null, null, null, "ALERT TEXT", "NOTICE TEXT");
```

### Changing the thresholds

[](#changing-the-thresholds)

You can change the threshold for setting Alerts and Notices as follows

```
    $thresholdAlert = 80;
    $thresholdNotice = 20;
    $identifier = new CardIdentifier(thresholdAlert, thresholdNotice);
```

### Changing the check level

[](#changing-the-check-level)

The library has multiple check levels (2 at present) which can be chosen by setting the `checkLevel`The check levels work as follows:

- Level 1 This check gets number that are typed in continuously without breakage with special characters. Using this check would result in a text such as `foo 123 456 bar` returning two suspected fragments `123` and `456`.
- Level 2 This check interprets numbers separated by special characters as one block and only breaks the numbers when they are separated by alphabets, for example `foo 123-45 bar 123 456 bar` would result in the fragments `12345` and `123456`

You can set the desired level of check as follows

```
    $checkLevel = 1;
    $identier = new CardIdentifier(null, null, checkLevel);
```

### Changing the probability weight of different checks

[](#changing-the-probability-weight-of-different-checks)

You can change the weight assigned to different checks of the process as follows:

```
    $probabilities = {
        'LUHN':60,
        'TEST_NUMBERS':100,
        'PROVIDERS':15,
        'LENGTH':15,
    };
    $identifier = new CardIdentifier(null, null, null, null, null, null, null, probabilities);
```

Note that you have to provide a value for all the different checks if you want to change the probabilities.

### Changing the constants used for performing checks

[](#changing-the-constants-used-for-performing-checks)

You can change the constants used for performing the checks. You can do the following by this:

- Change the minimum and maximum possible card lengths
- Change probability weight of different card lengths
- Add/Edit Regex checks used to identify cards as well as their probability weight
- Add new known test cards

This can be achieved as follows:

```
    $constants = new ValidationConstants();
    $constants->MIN_POSSIBLE_LENGTH = 4;
    $identifier = new CardIdentifier(null, null, null, null, null, null, null, null, constants);
```

References
----------

[](#references)

-
-

Copyright
---------

[](#copyright)

Published under MIT license. Copyright © 2017 Neblar Technologies

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/3b873f92a106465731e7518cad0e03aa2164147857ae9d7d0a0488dfb10d0ca5?d=identicon)[Neblar Technologies](/maintainers/Neblar%20Technologies)

---

Top Contributors

[![rijulg](https://avatars.githubusercontent.com/u/10543706?v=4)](https://github.com/rijulg "rijulg (4 commits)")

---

Tags

credit-cardextractionidentify-cardsphp

### Embed Badge

![Health badge](/badges/neblar-descardid/health.svg)

```
[![Health](https://phpackages.com/badges/neblar-descardid/health.svg)](https://phpackages.com/packages/neblar-descardid)
```

###  Alternatives

[chaoswey/taiwan-id-validator

台灣身分證、統一編號驗證

319.9k](/packages/chaoswey-taiwan-id-validator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
