Install the application with composer:
$ composer create-project davidianbonner/cli-phone-number-validator
To create a standalone PHAR of the application for deployment, run:
$ php number-validator app:build number-validator
This will output a .PHAR to the build
directory.
The validator comes with a pre-built GB & Channel Islands mobile command: validate:uk-mobile
. There are two ways to process and validate numbers:
Pass a list of phone numbers to the validator.
$ php number-validator validate:uk-mobile "07712345678" "07712341234" "07283 123 32"
Pass a file with a phone number per-line.
$ php number-validator validate:uk-mobile ./path/to/file --file
An output directory is required when using the standalone .PHAR:
$ php number-validator validate:uk-mobile ./path/to/file --file --output=/path/to/output/directory
New validators can be added with minimal effort. First create a new command in app/Commands
and extends the BaseValidatorCommand
.
<?php
namespace App\Commands;
class ValidateESFixedLineCommand extends BaseValidatorCommand
{
protected $signature = 'validate:es-fixedline
{source* : A list of numbers or files to validate against}
{--file : Specifies that the source is a list of files}
{--output= : Specifies that the output path}';
protected $description = 'Validate Spanish fixed line numbers and ouput to a CSV';
public function makeValidatorForNumer($number): PhoneNumberValidator
{
// The country code is only required when no dialing code is present in the number.
return app(PhoneNumberValidator::class)->make($number, 'ES');
}
public function isNumberValid(PhoneNumberValidator $validator): bool
{
return ($validator->isValidFixedLine() && $validator->isValidForCountry('ES'));
}
}
CLI Phone Number Validator is an open-sourced software licensed under the MIT license.