Filter and Validator for people name with multibyte string check support
MIT License
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.
composer require samsonasik/naming
'
and -
character if anyExamples:
Original name | Filtered name |
---|---|
<script>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 | Äx |
.
character-
character'
character.
characters-
characters'
charactersUsage 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" */
Contributions are very welcome. Please read CONTRIBUTING.md