Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function validateForm($validation, $required = array()) {
- foreach ($validation as $key => $config) {
- if ($_REQUEST[$key]) {
- if (!preg_match($_REQUEST[$key], $config["pattern"])) {
- return $config["error"];
- }
- } else if ($required[$key]) {
- return $config["error"];
- }
- }
- return true;
- }
- if (validateForm(array(
- "email" => array(
- "pattern" => "~([a-zA-Z0-9\-]+)@(.*?)~",
- "error" => "The email you have provided is shit, go away"
- ),
- "first" => array(
- "pattern" => "~([A-Za-z]+)~",
- "error" => "The first name provided is clearly made up, get a life"
- )
- ), array("email", "first"))) {
- echo "You got it ...";
- } else echo "You are a failure, I have no time for you ...";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement