<?php declare(strict_types=1);
namespace App\Base\Form;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Regex;
class PhoneType extends \Symfony\Component\Form\Extension\Core\Type\TextType
{
public function configureOptions(OptionsResolver $resolver)
{
$phonePattern = '^(\+7|8)\s\(\d{3}\)\s\d{3}-\d{2}-\d{2}';
$resolver->setDefaults([
'required' => false,
'constraints' => [
new Regex("/$phonePattern/"),
],
'attr' => [
'data-phone-field' => 'true',
'placeholder' => 'Номер телефона',
'pattern' => $phonePattern
]
]);
parent::configureOptions($resolver);
}
}