PHP code example of nanayawkumi / gh-phone-validator
1. Go to this page and download the library: Download nanayawkumi/gh-phone-validator 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/ */
nanayawkumi / gh-phone-validator example snippets
use Illuminate\Support\Facades\Validator;
$validator = Validator::make($request->all(), [
'phone' => '
use Nanayawkumi\GhPhoneValidator\Rules\GhPhone;
$validator = Validator::make($request->all(), [
'phone' => ['
// Store as raw (default)
$user = new User();
$user->phone = '024 123 4567';
$user->save(); // Stored as '0241234567'
// Store as E.164 format
use Nanayawkumi\GhPhoneValidator\Casts\GhPhoneCast;
class User extends Model
{
protected $casts = [
'phone' => GhPhoneCast::class . ':e164',
];
}
$user = new User();
$user->phone = '024 123 4567';
$user->save(); // Stored as '+233241234567'
// Retrieval works the same way regardless of storage format
$user = User::find(1);
echo $user->phone; // Output: '0241234567' (always raw when used as string)
echo $user->phone->e164(); // Output: '+233241234567'
use Nanayawkumi\GhPhoneValidator\GhPhoneValidator;
use Nanayawkumi\GhPhoneValidator\Enums\Network;
$network = GhPhoneValidator::network('0241234567');
if ($network === Network::MTN) {
// Do something
}
$network->label(); // MTN
$network->slug(); // mtn
use Nanayawkumi\GhPhoneValidator\Enums\Network;
$user->phone->network(); // Network enum (Network::MTN, Network::TELECEL, etc.)
// Use it in conditionals
if ($user->phone->network() === Network::MTN) {
// User is on MTN network
}
// Get network label
echo $user->phone->network()?->label(); // MTN
// Get network slug
echo $user->phone->network()?->slug(); // mtn