PHP code example of odolbeau / phone-number-bundle
1. Go to this page and download the library: Download odolbeau/phone-number-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
odolbeau / phone-number-bundle example snippets
// app/AppKernel.php
public function registerBundles()
{
$bundles = [
// ...
new Misd\PhoneNumberBundle\MisdPhoneNumberBundle()
];
}
{% if myPhoneNumber is phone_number_of_type('MOBILE') }} %} ... {% endif %}
use libphonenumber\PhoneNumberFormat;
use Misd\PhoneNumberBundle\Form\Type\PhoneNumberType;
use Symfony\Component\Form\FormBuilderInterface;
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('phoneNumber', PhoneNumberType::class, ['default_region' => 'GB', 'format' => PhoneNumberFormat::NATIONAL]);
}
use libphonenumber\PhoneNumberFormat;
use Misd\PhoneNumberBundle\Form\Type\PhoneNumberType;
use Symfony\Component\Form\FormBuilderInterface;
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('phoneNumber', PhoneNumberType::class, [
'widget' => PhoneNumberType::WIDGET_COUNTRY_CHOICE,
'country_choices' => ['GB', 'JE', 'FR', 'US'],
'preferred_country_choices' => ['GB', 'JE']
]);
}
use Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber as AssertPhoneNumber;
#[AssertPhoneNumber()]
private $phoneNumber;
use Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber as AssertPhoneNumber;
#[AssertPhoneNumber(defaultRegion: 'GB')]
private $phoneNumber;
use Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber as AssertPhoneNumber;
#[AssertPhoneNumber(regionPath: 'countryCode')]
private $phoneNumber;
private $countryCode;
public function getCountryCode()
{
return $this->countryCode;
}
use Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber as AssertPhoneNumber;
#[AssertPhoneNumber(type: [AssertPhoneNumber::MOBILE])]
private $mobilePhoneNumber;
#[AssertPhoneNumber(type: [AssertPhoneNumber::FIXED_LINE, AssertPhoneNumber::VOIP])]
private $fixedOrVoipPhoneNumber;
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.