Skip to content

Commit

Permalink
fix/test non-required empty email validation
Browse files Browse the repository at this point in the history
  • Loading branch information
CaptainN committed Sep 4, 2013
1 parent 36bdf07 commit 208f433
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions tests/validator_tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,13 @@ public function test_emailvalidator()

$field->value('[email protected]');
$this->assertTrue( $validator->isValid() );

$field->value('');
$this->assertFalse( $validator->isValid(),
"Empty value with required should be invalid." );

$field->required(false);
$this->assertTrue( $validator->isValid(),
"Empty value without required should be valid." );
}
}
2 changes: 1 addition & 1 deletion validators.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function isValid()
$valid = parent::isValid();
$field = $this->field;

if ( $valid ) {
if ( $field->value() ) {
if ( !preg_match( self::$email_pattern, $field->value() ) )
$this->errors[] = 'not a valid email address';
}
Expand Down

0 comments on commit 208f433

Please sign in to comment.