承接 clemdesign/php-mask 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

clemdesign/php-mask

Composer 安装命令:

composer require clemdesign/php-mask

包简介

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

README 文档

README

PHP Mask is a PHP library to make masks for a string.
It is an adapation of ngx-mask by JsDaddy.

Installation

PHP-Mask is available on composer:

composer require clemdesign/php-mask

Usage

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

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

Arguments

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

$maskExpression: Patterns

The patterns are used to filter $inputValue:

code meaning
0 digits (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

Special chars are used in mask expressions to format output:

character
/
(
)
.
:
-
space
+
,
@

$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

You can format a time according limit:

Mask meaning
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

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

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

Input Mask Output
Date is 20190526 9999-99-99 2019-05-26
Month is 20190526 0*.00 2019.05
04845798798 000.000.000-99 048.457.987-98
048457987 000.000.000-99 048.457.987-
0F6.g-lm AAAA 0F6g
a036s.D2F SSSS asDF

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:

License

Copyright (c) 2019 clemdesign.

For use under the terms of the MIT license.

clemdesign/php-mask 适用场景与选型建议

clemdesign/php-mask 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 107.89k 次下载、GitHub Stars 达 16, 最近一次更新时间为 2019 年 05 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 clemdesign/php-mask 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 clemdesign/php-mask 我们能提供哪些服务?
定制开发 / 二次开发

基于 clemdesign/php-mask 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 107.89k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 17
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 16
  • Watchers: 0
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-05-26