Ip.php 576 Bytes
Newer Older
doctrine's avatar
doctrine committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
<?php
class Doctrine_Validator_Ip {
    /**
     * @param Doctrine_Record $record
     * @param string $key
     * @param mixed $value
     * @param string $args
     * @return boolean
     */
    public function validate(Doctrine_Record $record, $key, $value, $args) {
        $e = explode(".",$request);
        if(count($e) != 4) return false;

        foreach($e as $k=>$v):
            if(! is_numeric($v)) return false;
            $v = (int) $v;
            if($v < 0 || $v > 255) return false;
        endforeach;
        return true;
    }
}
?>