Created a function to check email address

This commit is contained in:
Pierre 2018-05-21 10:54:39 +02:00
parent c44ee1cb1b
commit 993319057a

View File

@ -113,6 +113,25 @@ function postInt(string $name) : int {
return (int)$_POST[$name]; return (int)$_POST[$name];
} }
/**
* Get an email address specified in a $_POST request
*
* @param string $name The name of the post field containing the
* email address
* @return string The email address
*/
function postEmail(string $name) : string {
//Get the email as a string
$email = postString($name, 5);
//Check the email
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
Rest_fatal_error(400, "Specified email address is invalid !");
return $email;
}
/** /**
* Securely transform user given number (mixed) to integer (int) * Securely transform user given number (mixed) to integer (int)
* *