[add] Asserting email type

This commit is contained in:
Jose Pabl Domingo Aramburo Sanchez 2018-08-12 17:15:39 -06:00
parent 79059fb91b
commit abd8168dbf
2 changed files with 15 additions and 0 deletions

View File

@ -138,6 +138,7 @@ class EmployeeApplication{
$email = $requestData['email'];
$this->asserts->isNotEmpty($email, "The email can't be empty.");
$this->asserts->betweenLength($email, 1, 100, "The middle name must have a length between 1 and 100 characters.");
$this->asserts->isEmail($email, "The email isn't in a correct format");
$phone = $requestData['phone'];
$this->asserts->isNotEmpty($phone, "The phone number can't be empty.");
@ -409,6 +410,7 @@ class EmployeeApplication{
$email = $requestData['email'];
$this->asserts->isNotEmpty($email, "The email can't be empty.");
$this->asserts->betweenLength($email, 1, 100, "The middle name must have a length between 1 and 100 characters.");
$this->asserts->isEmail($email, "The email isn't in a correct format");
$phone = $requestData['phone'];
$this->asserts->isNotEmpty($phone, "The phone number can't be empty.");

View File

@ -56,5 +56,18 @@ class Asserts{
throw new Exception($errorMessage);
}
}
/**
* Compares a string against a regex to determine if it's an email
*
* @param $string string
* @param $errorMessage string
* @throws Exception
*/
function isEmail($string, $errorMessage){
if(!filter_var($string, FILTER_VALIDATE_EMAIL)){
throw new Exception($errorMessage);
}
}
}
?>