- strpos: documentation ( source)
- filter_var: documentation ( source)
<?php
class customException extends Exception {
public function errorMessage() {
$errorMsg = 'error on line ' .$this->getLine(). ' in '.$this->getFle().': <b>' .$this->geMessage().'</b> is not a valid e-mail address';
return $errorMsg;
}
}
$emial = "someone@example.com";
try {
if(filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
throw new customException($emial);
}
if(strpos($email,"example") !== FALSE) {
throw new Exception("emial is an example e-mail");
}
}
catch (customException $e) {
echo $e->errorMessage();
}
catch(Excception $e) {
echo $e->getMessage();
}
?>