Validation Patterns
Email Format
Use PHP's filter helper to check an email shape.
email-format
`filter_var` can validate common scalar formats. The example converts the result into a simple label for replay.
Email Format
email_format.php
Replay: real traced execution (multi-file project)
<?php
$email = "ada@example.com";
$checked = filter_var($email, FILTER_VALIDATE_EMAIL);
$status = $checked === false ? "invalid" : "valid";
echo "email=" . $email . "\n";
echo "status=" . $status . "\n";
<?php
$email = "bad";
$checked = filter_var($email, FILTER_VALIDATE_EMAIL);
$status = $checked === false ? "invalid" : "valid";
echo "email=" . $email . "\n";
echo "status=" . $status . "\n";
<?php
$email = "lin@example.org";
$checked = filter_var($email, FILTER_VALIDATE_EMAIL);
$status = $checked === false ? "invalid" : "valid";
echo "email=" . $email . "\n";
echo "status=" . $status . "\n";
$email ← ada@example.com, $checked ← ada@example.com, $status ← valid
1<?php2$email→ ada@example.com = "ada@example.com"; //@email="bad", "lin@example.org"3$checked→ ada@example.com = filter_var($emailada@example.com, FILTER_VALIDATE_EMAIL);4$status→ valid = $checkedada@example.com === false ? "invalid" : "valid";56echo "email=" . $emailada@example.com . "\n";7echo "status=" . $statusvalid . "\n";outputemail=ada@example.com status=valid
$email ← bad, $checked ← (empty), $status ← invalid
1<?php2$email→ bad = "bad";3$checked→ (empty) = filter_var($emailbad, FILTER_VALIDATE_EMAIL);4$status→ invalid = $checked(empty) === false ? "invalid" : "valid";56echo "email=" . $emailbad . "\n";7echo "status=" . $statusinvalid . "\n";outputemail=bad status=invalid
$email ← lin@example.org, $checked ← lin@example.org, $status ← valid
1<?php2$email→ lin@example.org = "lin@example.org";3$checked→ lin@example.org = filter_var($emaillin@example.org, FILTER_VALIDATE_EMAIL);4$status→ valid = $checkedlin@example.org === false ? "invalid" : "valid";56echo "email=" . $emaillin@example.org . "\n";7echo "status=" . $statusvalid . "\n";outputemail=lin@example.org status=valid