static public function validateByRule($value, $rule, $failOnError = true)
    {
        $valid = false;

        switch ($rule)
        {
            case self::EMAIL:
            {
                $valid = filter_var($value, FILTER_VALIDATE_EMAIL);
                break;
            }
            case self::IP:
            {
                $valid = filter_var($value, FILTER_VALIDATE_IP);
                break;
            }
            case self::URL:
            {
                $valid = filter_var($value, FILTER_VALIDATE_URL);
                break;
            }
            case self::MONTH:
            {
                $valid = in_array($value, range(1, 12));
                break;
            }
            case self::COUNTRY:
            {
                $valid = RegionFinder::hasCountryByCode($value);
                break;
            }
            case self::STATE:
            {
                $valid = RegionFinder::hasStateByCode($value);
                break;
            }
            default:
            {
                if (isset(static::$ruleRegExps[$rule]))
                {
                    $valid = static::validateByRegExp($value, static::$ruleRegExps[$rule], $failOnError);
                }
                else
                {
                    $valid = static::validateByRegExp($value, $rule, $failOnError);
                }
            }
        }

        if ($valid !== false)
        {
            return true;
        }
        elseif ($failOnError === true)
        {
            throw new ValidationException("Value '{$value}' does not match rule '{$rule}'");
        }
        else
        {
            return false;
        }
    }
static public function validateByRule($value, $rule, $failOnError = true)
    {
        $valid = false;

        switch ($rule)
        {
            case self::EMAIL:
            {
                $valid = filter_var($value, FILTER_VALIDATE_EMAIL);
                break;
            }
            case self::IP:
            {
                $valid = filter_var($value, FILTER_VALIDATE_IP);
                break;
            }
            case self::URL:
            {
                $valid = filter_var($value, FILTER_VALIDATE_URL);
                break;
            }
            case self::MONTH:
            {
                $valid = in_array($value, range(1, 12));
                break;
            }
            case self::COUNTRY:
            {
                $valid = RegionFinder::hasCountryByCode($value);
                break;
            }
            case self::STATE:
            {
                $valid = RegionFinder::hasStateByCode($value);
                break;
            }
            default:
            {
                if (isset(static::$ruleRegExps[$rule]))
                {
                    $valid = static::validateByRegExp($value, static::$ruleRegExps[$rule], $failOnError);
                }
                else
                {
                    $valid = static::validateByRegExp($value, $rule, $failOnError);
                }
            }
        }

        if ($valid !== false)
        {
            return true;
        }
        elseif ($failOnError === true)
        {
            throw new ValidationException("Value '{$value}' does not match rule '{$rule}'");
        }
        else
        {
            return false;
        }
    }
static public function validateByRule ( $ value , $ rule , $ failOnError = true ) { $ valid = false ; switch ( $ rule ) { case self :: EMAIL : { $ valid = filter_var ( $ value , FILTER_VALIDATE_EMAIL ) ; break ; } case self :: IP : { $ valid = filter_var ( $ value , FILTER_VALIDATE_IP ) ; break ; } case self :: URL : { $ valid = filter_var ( $ value , FILTER_VALIDATE_URL ) ; break ; } case self :: MONTH : { $ valid = in_array ( $ value , range ( 1 , 12 ) ) ; break ; } case self :: COUNTRY : { $ valid = RegionFinder :: hasCountryByCode ( $ value ) ; break ; } case self :: STATE : { $ valid = RegionFinder :: hasStateByCode ( $ value ) ; break ; } default : { if ( isset ( static :: $ ruleRegExps [ $ rule ] ) ) { $ valid = static :: validateByRegExp ( $ value , static :: $ ruleRegExps [ $ rule ] , $ failOnError ) ; } else { $ valid = static :: validateByRegExp ( $ value , $ rule , $ failOnError ) ; } } } if ( $ valid !== false ) { return true ; } elseif ( $ failOnError === true ) { throw new ValidationException ( "Value '{$value}' does not match rule '{$rule}'" ) ; } else { return false ; } }
Validates value by given rule.
Rule can be one of Validator constants or regExp.

@param       string      $value              Value for validation
@param       string      $rule               Rule for validation
@param       boolean     $failOnError        Throw exception on invalid value or not

@return      boolean                         Validation result

@throws      ValidationException             Value does not match rule (if $failOnError == true)
Validates value by given rule . Rule can be one of Validator constants or regExp .