src/Base/Form/PhoneType.php line 8

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace App\Base\Form;
  3. use Symfony\Component\OptionsResolver\OptionsResolver;
  4. use Symfony\Component\Validator\Constraints\Regex;
  5. class PhoneType extends \Symfony\Component\Form\Extension\Core\Type\TextType
  6. {
  7.     public function configureOptions(OptionsResolver $resolver)
  8.     {
  9.         $phonePattern '^(\+7|8)\s\(\d{3}\)\s\d{3}-\d{2}-\d{2}';
  10.         $resolver->setDefaults([
  11.             'required' => false,
  12.             'constraints' => [
  13.                 new Regex("/$phonePattern/"),
  14.             ],
  15.             'attr' => [
  16.                 'data-phone-field' => 'true',
  17.                 'placeholder' => 'Номер телефона',
  18.                 'pattern' => $phonePattern
  19.             ]
  20.         ]);
  21.         parent::configureOptions($resolver);
  22.     }
  23. }