<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
settermjd / laminas-twilio-phone-number-validator example snippets
use Settermjd\Validator\VerifyPhoneNumber;
use Twilio\Rest\Client;
$validator = new VerifyPhoneNumber(new Client(
`<YOUR_TWILIO_ACCOUNT_SID>`,
`<YOUR_TWILIO_AUTH_TOKEN>`,
));
if ($validator->isValid($email)) {
// The phone number is valid, so do what you want knowing that.
} else {
// The phone number is not valid, so show the reasons why.
foreach ($validator->getMessages() as $messageId => $message) {
printf("Validation failure '%s': %s\n", $messageId, $message);
}
}
use Laminas\InputFilter\InputFilter;
use Laminas\InputFilter\Input;
use Laminas\Validator;
use Settermjd\Validator\VerifyPhoneNumber;
use Twilio\Rest\Client;
$phoneNumber = new Input('phone_number');
$phoneNumber->getValidatorChain()
->attach(
new VerifyPhoneNumber(
new Client(
`<TWILIO_ACCOUNT_SID>`,
`<TWILIO_AUTH_TOKEN>`,
)
)
);
$inputFilter = new InputFilter();
$inputFilter->add($phoneNumber);
$inputFilter->setData($_POST);
if ($inputFilter->isValid()) {
echo "The form is valid\n";
} else {
echo "The form is not valid\n";
foreach ($inputFilter->getInvalidInput() as $error) {
print_r($error->getMessages());
}
}
use Laminas\InputFilter\InputFilter;
use Laminas\InputFilter\Input;
use Laminas\Validator;
use Settermjd\InputFilter\QueryParametersInputFilter;
use Settermjd\Validator\VerifyPhoneNumber;
use Twilio\Rest\Client;
$inputFilter = new QueryParametersInputFilter();
$inputFilter->setData($suppliedQueryParameters);
if ($inputFilter->isValid()) {
$validator = new VerifyPhoneNumber(
twilioClient: new Client(
`<YOUR_TWILIO_ACCOUNT_SID>`,
`<YOUR_TWILIO_AUTH_TOKEN>`,
),
queryParameters: $inputFilter->getValues(),
);
if ($validator->isValid($email)) {
// The phone number is valid, so do what you want knowing that.
} else {
// The phone number is not valid, so show the reasons why.
foreach ($validator->getMessages() as $messageId => $message) {
printf("Validation failure '%s': %s\n", $messageId, $message);
}
}
}
use Laminas\Cache\Psr\SimpleCache\SimpleCacheDecorator;
use Laminas\Cache\Service\StorageAdapterFactoryInterface;
use Psr\Container\ContainerInterface;
use Settermjd\Validator\VerifyPhoneNumber;
use Twilio\Rest\Client;
/** @var ContainerInterface $container */
$container = null; // can be any configured PSR-11 container
$storageFactory = $container->get(StorageAdapterFactoryInterface::class);
$storage = $storageFactory->create('apc');
$validator = new VerifyPhoneNumber(
twilioClient: new Client(`<YOUR_TWILIO_ACCOUNT_SID>`, `<YOUR_TWILIO_AUTH_TOKEN>`),
cache: new SimpleCacheDecorator($storage),
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.