PHP code example of 104corp / validation

1. Go to this page and download the library: Download 104corp/validation 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/ */

    

104corp / validation example snippets




use Corp104\Validation\Facade;
use Corp104\Validation\Validators\StringType;

$pid = 123;

if (Facade::isValid(StringType::class, $pid)) {
    echo '格式正確';
} else {
    echo '格式不正確';
}



use Corp104\Validator;
use Corp104\Validator\Validator\StringType;

$pid = 123;
$exception = new InvalidArgumentException('格式錯誤');

try {
    Facade::assert(StringType::class, $pid, $exception);
} catch (InvalidArgumentException $e) {
    echo $e->getMessage();  // 顯示 '格式錯誤'
}