Source

teampenta-sfrest / src / TP / CoreBundle / Validator / PhoneNumberValidator.php

The branch 'add-validator' does not exist.
Full commit
<?php
namespace TP\CoreBundle\Validator;

use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;

class PhoneNumberValidator extends ConstraintValidator
{
    function validate($value, Constraint $constraint)
    {
        if (null === $value ||$value === '') {
            return true;
        }

        if (preg_match('/^\d$/', $value)) {
            return true;
        }

        $this->setMessage($constraint->message, array('{{ value }}'=>$value));
        return false;
    }
}