Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
<?php function validateForm(array $data): array { $errors = []; // Email if (!filter_var($data["email"], FILTER_VALIDATE_EMAIL)) { $errors["email"] = "Invalid email"; } // Phone (US format) if (!preg_match("/^\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$/", $data["phone"])) { $errors["phone"] = "Invalid phone number"; } // Password strength if (!preg_match("/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d).{8,}$/", $data["password"])) { $errors["password"] = "Password must be 8+ chars with upper, lower, and digit"; } return $errors; }
Result
Open