samsonasik / naming
Naming Filter and Validator for people name
3.0.1
2023-01-15 22:06 UTC
Requires
- php: ^8.1
- laminas/laminas-filter: ^2.31
- laminas/laminas-validator: ^2.29
- samsonasik/array-lookup: ^1.3
- symfony/polyfill-mbstring: ^1.27
- webmozart/assert: ^1.11
Requires (Dev)
- kahlan/kahlan: ^5.2.2
- laminas/laminas-coding-standard: ^2.5
- php-coveralls/php-coveralls: ^2.5.3
- phpstan/phpstan: ^1.9.11
- phpstan/phpstan-webmozart-assert: ^1.2.2
- rector/rector: dev-main
- squizlabs/php_codesniffer: ^3.7.1
README
Naming is a library that has filter and validator for people name with multibyte string check support, extends the Laminas
filter and validator, while it can be used as standalone.
Installation
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 any
Examples:
Validation 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 word
Usage with laminas-form instance:
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:
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