E-mail validator
Added an e-mail validator to the form package. The validator is really primitive and will only accept a small subset of email addresses, but I needed one *now*.
This commit is contained in:
parent
f80d739f5d
commit
62a4d0a391
2 changed files with 24 additions and 0 deletions
|
@ -22,3 +22,4 @@ $package[ 'extras' ][] = 'Modifier_TrimString';
|
||||||
$package[ 'extras' ][] = 'Validator_StringLength';
|
$package[ 'extras' ][] = 'Validator_StringLength';
|
||||||
$package[ 'extras' ][] = 'Validator_InArray';
|
$package[ 'extras' ][] = 'Validator_InArray';
|
||||||
$package[ 'extras' ][] = 'Validator_IntValue';
|
$package[ 'extras' ][] = 'Validator_IntValue';
|
||||||
|
$package[ 'extras' ][] = 'Validator_Email';
|
||||||
|
|
|
@ -99,3 +99,26 @@ class Validator_IntValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class Validator_Email
|
||||||
|
implements FieldValidator
|
||||||
|
{
|
||||||
|
private $errorText;
|
||||||
|
|
||||||
|
public function __construct( $errorText )
|
||||||
|
{
|
||||||
|
$this->errorText = $errorText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validate( $value )
|
||||||
|
{
|
||||||
|
if ( preg_match( "/^[a-zA-Z0-9\._-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/" , $value ) ) {
|
||||||
|
list( $username , $domain ) = split( '@' , $value );
|
||||||
|
if ( checkdnsrr( $domain , 'MX' ) ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return array( $this->errorText );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue