public function testIsIP() { $this->assertTrue(SpoonFilter::isIp('127.0.0.1')); $this->assertTrue(SpoonFilter::isIp('192.168.1.101')); $this->assertFalse(SpoonFilter::isIp('kfsl')); $this->assertFalse(SpoonFilter::isIp(array())); }
/** * Checks if this field is a proper ip address. * * @return bool * @param string[optional] $error The error message to set. */ public function isIp($error = null) { // filled if ($this->isFilled()) { // post/get data $data = $this->getMethod(true); // validate if (!isset($data[$this->attributes['name']]) || !SpoonFilter::isIp($data[$this->attributes['name']])) { if ($error !== null) { $this->setError($error); } return false; } return true; } // not submitted if ($error !== null) { $this->setError($error); } return false; }