Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/samsonasik/naming
Filter and Validator for people name with multibyte string check support
https://github.com/samsonasik/naming
filter laminas mbstring multibyte name naming people php special standalone validator zf zf2 zf3
Last synced: 2 days ago
JSON representation
Filter and Validator for people name with multibyte string check support
- Host: GitHub
- URL: https://github.com/samsonasik/naming
- Owner: samsonasik
- License: mit
- Created: 2019-02-22T14:32:43.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-09-08T17:02:23.000Z (25 days ago)
- Last Synced: 2024-09-08T18:39:19.772Z (25 days ago)
- Topics: filter, laminas, mbstring, multibyte, name, naming, people, php, special, standalone, validator, zf, zf2, zf3
- Language: PHP
- Size: 67.4 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
Naming
======[![Latest Version](https://img.shields.io/github/release/samsonasik/Naming.svg?style=flat-square)](https://github.com/samsonasik/Naming/releases)
![ci build](https://github.com/samsonasik/Naming/workflows/ci%20build/badge.svg)
[![Code Coverage](https://codecov.io/gh/samsonasik/Naming/branch/master/graph/badge.svg)](https://codecov.io/gh/samsonasik/Naming)
[![PHPStan](https://img.shields.io/badge/style-level%20max-brightgreen.svg?style=flat-square&label=phpstan)](https://github.com/phpstan/phpstan)
[![Downloads](https://img.shields.io/packagist/dt/samsonasik/naming.svg?style=flat-square)](https://packagist.org/packages/samsonasik/naming)Naming is a library that has filter and validator for people name with multibyte string check support, extends the [`Laminas`](https://getlaminas.org/) filter and validator, while it can be used as standalone.
Installation
------------```sh
composer require samsonasik/naming
```Filter Flow
------------ Strip Tags
- String Trim
- String To Upper first letter in each word with set lower case after that
- Replace double space to single space
- String To Upper after `'` and `-` character if anyExamples:
| Original name | Filtered name
|----------------------------------|-----------------
| \Abdul | Abdul
| ABduL | Abdul
| aBDUL m. ikHsan | Abdul M. Ikhsan
| abdul Malik I | Abdul Malik I
| D'lilah | D'Lilah
| Veli-matti | Veli-Matti
| äX | ÄxValidation checks
------------------ Allowed characters: letters, hyphens, apostrophe, spaces, full stops.
- Not allowed:
- include number
- special characters
- single `.` character
- single `-` character
- single `'` character
- consecutive `.` characters
- consecutive `-` characters
- consecutive `'` characters
- full stops not in the last of each wordUsage with laminas-form instance:
```php
use Naming\Filter;
use Naming\Validator;
use Laminas\Form\Element\Text;
use Laminas\Form\Form;
use Laminas\InputFilter\InputFilterProviderInterface;class ContactForm extends Form implements InputFilterProviderInterface
{
public function init()
{
$this->add([
'type' => Text::class,
'name' => 'fullname',
'options' => [
'label' => 'Full name',
],
]);
}public function getInputFilterSpecification()
{
return [
[
'name' => 'fullname',
'required' => true,
'filters' => [
[
'name' => Filter\Naming::class
],
],
'validators' => [
[
'name' => Validator\Naming::class,
],
],
],
];
}
}
```Using standalone:
```php
use Naming\Filter;
use Naming\Validator;include 'vendor/autoload.php';
// ... VALID
$filtered = (new Filter\Naming())->filter('Abdul malik ikhsan');
$validator = new Validator\Naming();echo $filtered; // Abdul Malik Ikhsan
var_dump($validator->isValid($filtered)); // true// ... INVALID
$filtered = (new Filter\Naming())->filter('Abdul....');
$validator = new Validator\Naming();echo $filtered; // Abdul....
var_dump($validator->isValid($filtered)); // false
var_dump(\current($validator->getMessages())); /* "Consecutive "."s are not allowed" */
```Contributing
------------
Contributions are very welcome. Please read [CONTRIBUTING.md](https://github.com/samsonasik/Naming/blob/master/CONTRIBUTING.md)