Advertisement
Guest User

Untitled

a guest
Aug 13th, 2013
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. <?php
  2. function validateForm($validation, $required = array()) {
  3. foreach ($validation as $key => $config) {
  4. if ($_REQUEST[$key]) {
  5. if (!preg_match($_REQUEST[$key], $config["pattern"])) {
  6. return $config["error"];
  7. }
  8. } else if ($required[$key]) {
  9. return $config["error"];
  10. }
  11. }
  12. return true;
  13. }
  14.  
  15. if (validateForm(array(
  16. "email" => array(
  17. "pattern" => "~([a-zA-Z0-9\-]+)@(.*?)~",
  18. "error" => "The email you have provided is shit, go away"
  19. ),
  20. "first" => array(
  21. "pattern" => "~([A-Za-z]+)~",
  22. "error" => "The first name provided is clearly made up, get a life"
  23. )
  24. ), array("email", "first"))) {
  25. echo "You got it ...";
  26. } else echo "You are a failure, I have no time for you ...";
  27. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement