<?php
/* Creating Custom Exception Class */ class customException extends Exception { public function errorMessage() { //error message $errorMsg = 'Error on line '.$this->getLine().' in '.$this->getFile() .': <b>'.$this->getMessage().'</b> is not a valid E-Mail address'; return $errorMsg; } } /* Creating Custom Exception Class */ $email = "[email protected]"; try { //check if if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { //throw exception if email is not valid throw new customException($email); } echo "Email Id is Valid"; } catch (customException $e) { //display custom message echo $e->errorMessage(); } ?>
0 Comments
Leave a Reply. |