junker/phone-number-validator

PhoneNumber validation component for Symfony based frameworks (Symfony, Silex, Drupal etc.)

dev-master 2021-08-16 12:43 UTC

This package is auto-updated.

Last update: 2024-10-16 19:29:07 UTC


README

PhoneNumber validation component for Symfony based frameworks (Symfony, Silex, Drupal etc.)

Installation

The best way to install phone-number-validator is to use a Composer:

php composer.phar require junker/phone-number-validator

Examples

use Junker\PhoneNumberValidator\Constraints\PhoneNumber as AssertPhoneNumber;

class AppController
{
    ...

    protected function validate($data)
    { 
        $fields = [
            'phone' => new AssertPhoneNumber([
                        'message' => 'Wrong phone number',
                        'type' => "mobile", # //optional
                        'defaultRegion' => "GB", # //optional
            ])
        ];

        $constraint = new Assert\Collection([
            'fields' => $fields
        ]);

        return $app['validator']->validate($data, $constraint);
    }

    ...
}

Based on PhoneNumberBundle (https://github.com/misd-service-development/phone-number-bundle)