Example #1
0
 public function validate(Jam_Validated $model, $attribute, $value)
 {
     if ($this->regex !== NULL and !preg_match($this->regex, $value)) {
         $model->errors()->add($attribute, 'format_regex', array(':regex' => $this->regex));
     }
     if ($this->filter !== NULL and !(filter_var($value, $this->filter, $this->flag) !== FALSE)) {
         $model->errors()->add($attribute, 'format_filter', array(':filter' => $this->filter));
     }
     if ($this->ip === TRUE and !Valid::ip($value)) {
         $model->errors()->add($attribute, 'format_ip');
     }
     if ($this->url === TRUE and !Valid::url($value)) {
         $model->errors()->add($attribute, 'format_url');
     }
     if ($this->email === TRUE and !Valid::email($value)) {
         $model->errors()->add($attribute, 'format_email');
     }
     if ($this->credit_card === TRUE and !Valid::credit_card($value)) {
         $model->errors()->add($attribute, 'format_credit_card');
     }
 }
Example #2
0
 /**
  * Tests Valid::ip()
  *
  * @test
  * @dataProvider  provider_ip
  * @param string  $input_ip
  * @param boolean $allow_private
  * @param boolean $expected_result
  */
 public function test_ip($input_ip, $allow_private, $expected_result)
 {
     $this->assertEquals($expected_result, Valid::ip($input_ip, $allow_private));
 }