PHP code example of fingermessenger / formvalidation

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

    

fingermessenger / formvalidation example snippets


use FingerMessenger\FormValidation;

class FormController
{
    use FormValidation;

    public function myFilter($data)
    {
        return substr($data, 0, 20);
    }

    public function checkData($data)
    {
        if (is_string($data)) {
            return true;
        }
        return false;
    }

    public function run()
    {
        $data = array(
            "title" => " jfilsk93808ii4okemg9fk "
        );

        $rules = array(
            "title" => array(
                "filter" => array("filterTrim", "myFilter"),
                "rules"  => array(
                    array("type" => "isNotNull", "msg" => "title is null"),
                    array("type" => "isEmail", "msg" => "title is not email"),
                    array("type" => "isUrl", "msg" => "title is not url"),
                    array("type" => "isChineseCharacter", "msg" => "title is not chinese"),
                    array("type" => "isInvalidStr", "msg" => "title is not invalid"),
                    array("type" => "isPostNum", "msg" => "title is not post num"),
                    array("type" => "isPersonalCard", "msg" => "title is not personal card"),
                    array("type" => "isIPv4", "msg" => "title is not ipv4"),
                    array("type" => "isMobile", "msg" => "title is not mobile num"),
                    array("type" => "isLength", "param" => array(6, 30), "msg" => "title length must betwen 6 and 30"),
                    array("type" => "checkData", "msg" => "title is not string"),
                )
            )
        );

        if (!$this->validationRun()) {
            echo $this->getValidationError();
        }
    }
}