$email = test_input($_POST["email"]); // check if email address is well-formed if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $emailErr = "Invalid email format"; }
$url = test_input($_POST["url"]); // check if URL address syntax is valid if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$url)) { $urlErr = "Invalid URL"; }
$name = test_input($_POST["name"]); // check if name only contains letters and whitespace if (!preg_match("/^[a-zA-Z ]*$/",$name)) { $nameErr = "Only letters and white space allowed"; }Package/library: Regular Expressions (PCRE) Overall, the PHP core language provides basic Form validation functions, whereas libraries such as Filters in the PHP Filter Extension and Regular Expressions (PCRE) provide advanced and more flexible Form validation capabilities.