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;
        }
    }