$phone_number = $_POST['phone_number']; if (!preg_match("/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/", $phone_number)) { echo "Invalid phone number format!"; }
$email = $_POST['email']; if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo "Invalid email address!"; }
composer require respect/validation
use Respect\Validation\Validator as v; $email = $_POST['email']; if (!v::email()->validate($email)) { echo "Invalid email address!"; }This code uses the `email` validation rule provided by the Respect\Validation library to validate the input email address. If it is not valid, an error message is displayed.