PHP code example of nanayawkumi / nyk-input-validator

1. Go to this page and download the library: Download nanayawkumi/nyk-input-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 / nyk-input-validator example snippets


use Nanayawkumi\InputValidator\Facades\Input;

$username = Input::username('  johnny_doe  '); // "johnny_doe"
$email    = Input::email('[email protected]'); // "[email protected]"
$phone    = Input::phone('+233 24 123 4567'); // "0241234567"
$first    = Input::firstName('Ama');
$last     = Input::lastName("O'Brien");
$full     = Input::fullName('Jean-Pierre Mensah');
$card     = Input::ghanaCard('gha1234567890'); // "GHA-123456789-0"
$voter    = Input::voterId('9001330422');
$passport = Input::passport('g1234567'); // "G1234567"
$url      = Input::url('https://example.com');

use Nanayawkumi\InputValidator\Phone\GhPhoneValidator;

GhPhoneValidator::normalize('+233241234567');     // 0241234567
GhPhoneValidator::formatNational('0241234567');   // 024 123 4567
GhPhoneValidator::formatInternational(...);       // +233 24 123 4567
GhPhoneValidator::formatE164(...);                // +233241234567
GhPhoneValidator::network('0241234567');          // Network::MTN

$phone = Input::phone('0241234567');
$phone->national();
$phone->international();
$phone->e164();
$phone->network();

$request->validate([
    'username' => [',
    'phone' => ['bsite' => ['nullable', 'nyk_url'],
]);

use Nanayawkumi\InputValidator\Rules\Username;
use Nanayawkumi\InputValidator\Rules\Email;
use Nanayawkumi\InputValidator\Rules\GhPhone;
use Nanayawkumi\InputValidator\Rules\SecureUrl;

$request->validate([
    'username' => ['

use Nanayawkumi\InputValidator\Casts\GhPhoneCast;
use Nanayawkumi\InputValidator\Casts\SanitizedCast;

protected function casts(): array
{
    return [
        'phone' => GhPhoneCast::class,           // or GhPhoneCast::class.':e164'
        'username' => SanitizedCast::class.':username',
        'email' => SanitizedCast::class.':email',
        'ghana_card' => SanitizedCast::class.':ghana_card',
    ];
}

use Nanayawkumi\InputValidator\Livewire\SanitizesInputs;

class RegisterForm extends Component
{
    use SanitizesInputs;

    public string $username = '';
    public string $email = '';

    protected function inputSanitizers(): array
    {
        return [
            'username' => 'username',
            'email' => 'email',
        ];
    }

    protected function rules(): array
    {
        return [
            'username' => ['