PHPackages                             clemdesign/php-mask - 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. clemdesign/php-mask

ActiveLibrary

clemdesign/php-mask
===================

PHP-Mask is a PHP library to make masks on string.

1.0.0(6y ago)16101.9k↓25%2MITPHPPHP &gt;=7.0.0

Since May 26Pushed 6y agoCompare

[ Source](https://github.com/clemdesign/php-mask)[ Packagist](https://packagist.org/packages/clemdesign/php-mask)[ RSS](/packages/clemdesign-php-mask/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

php-mask
========

[](#php-mask)

PHP Mask is a PHP library to make masks for a string.
It is an adapation of [ngx-mask](https://github.com/JsDaddy/ngx-mask) by [JsDaddy](https://github.com/JsDaddy).

Installation
------------

[](#installation)

PHP-Mask is available on composer:

```
composer require clemdesign/php-mask

```

Usage
-----

[](#usage)

In your PHP application, use the static method `apply` of Mask:

```
$output = \Clemdesign\PhpMask\Mask::apply($inputValue, $maskExpression, $config);
```

### Arguments

[](#arguments)

- `$inputValue`: string - The input value to apply mask.
- `$maskExpression`: string - The mask expression for $output.
- `$config`: array - The configuration for operation

#### $maskExpression: Patterns

[](#maskexpression-patterns)

The patterns are used to filter $inputValue:

codemeaning0digits (like 0 to 9 numbers)**9**digits (like 0 to 9 numbers), but optional**A**letters (uppercase or lowercase) and digits**S**only letters (uppercase or lowercase)#### $maskExpression: Special chars

[](#maskexpression-special-chars)

Special chars are used in mask expressions to format output:

character/().:-**space**+,@#### $maskExpression: Thousand separator

[](#maskexpression-thousand-separator)

You can format a number in thousand separator and control precision.

The mask keys are:

- `separator`: Input `1234.56` is ouputed as `1 234.56`
- `dot_separator`: Input `1234,56` is ouputed as `1.234,56`
- `comma_separator`: Input `1234.56` is ouputed as `1,234.56`

To manage precision, keys shall be suffixed by `.{Number}`.

Example:

- `separator.1`: Input `1234.56743` is ouputed as `1 234.5`
- `dot_separator.4`: Input `1234,56743` is ouputed as `1.234,5674`
- `comma_separator.2`: Input `1234.56743` is ouputed as `1,234.56`

#### $maskExpression: Time validation

[](#maskexpression-time-validation)

You can format a time according limit:

Maskmeaning**H**Input value shall be inside 0 and 2.**h**Input value shall be inside 0 and 3.**m**Input value shall be inside 0 and 5.**s**Input value shall be inside 0 and 5.#### $maskExpression: Percent validation

[](#maskexpression-percent-validation)

You can format a value from `$inputValue` as a percent and manage the precision.

Use the key `percent` to have a extract value from `$inputValue` within 0 to 100.

Suffix the key with `.{Number}` to manage precision (`percent.2`).

Example:

```
$output = \Clemdesign\PhpMask\Mask::apply("99.4125", "percent.2");

// $output contains: 99.41
```

#### $config: Prefix and suffix

[](#config-prefix-and-suffix)

You have possibility to set suffix and prefix in output:

```
$output = \Clemdesign\PhpMask\Mask::apply("0102030405", "00 00 00 00 00", array(
  "prefix" => "My phone is ",
  "suffix" => "!"
));

// $output contains: My phone is 01 02 03 04 05!
```

Examples
--------

[](#examples)

InputMaskOutputDate is 201905269999-99-992019-05-26Month is 201905260\*.002019.0504845798798000.000.000-99048.457.987-98048457987000.000.000-99048.457.987-0F6.g-lmAAAA0F6ga036s.D2FSSSSasDFContributing
------------

[](#contributing)

If you think any implementation are just not the best, feel free to submit ideas and pull requests. All your comments and suggestion are welcome.

Credits:
--------

[](#credits)

- [ngx-mask](https://github.com/JsDaddy/ngx-mask) of [JsDaddy](https://github.com/JsDaddy)

License
-------

[](#license)

Copyright (c) 2019 [clemdesign](https://github.com/clemdesign/).

For use under the terms of the [MIT](http://www.opensource.org/licenses/mit-license.php) license.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community7

Small or concentrated contributor base

Maturity54

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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2549d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1578d982300f889de337e3b3edebefc4acb47ed633c55f17e303c466ade7a3c2?d=identicon)[clemdesign](/maintainers/clemdesign)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/clemdesign-php-mask/health.svg)

```
[![Health](https://phpackages.com/badges/clemdesign-php-mask/health.svg)](https://phpackages.com/packages/clemdesign-php-mask)
```

PHPackages © 2026

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