junker/phone-number-validator

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

dev-master 2018-01-27 18:15 UTC

This package is auto-updated.

Last update: 2020-09-10 13:03:10 UTC


README

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

Installation

The best way to install JSendResponse 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)