Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Vaildation Functions
- // Presence validation
- function has_presence($value) { // returns true if it has presence and false if empty.
- return isset($value) && $value !== "";
- }
- // String length validation
- function has_maximum_length($value, $maxsize) { // returns true if object is less than maximum length
- return strlen($value) <= $maxsize;
- }
- // Type validation
- // Inclusion in a set validation
- function has_membership_in($value, $set) { // returns true if item belongs to the set.
- return in_array($value, $set);
- }
- function has_gender($value) { // returns true if gender is male or female.
- $genderset = array("male", "female");
- return in_array($value, $genderset);
- }
- /*
- // Format validation
- // preg_match($regex, $subject)
- if (preg_match( , )) {
- // match found
- } else {
- // match not found
- }
- */
- // Display form errors
- function form_errors($errors=array()) {
- $output = "";
- if (!empty($errors)) {
- $output .= "<div class=\"error\">";
- $output .= "<ul>";
- foreach ($errors as $key => $error) {
- $output .= "<li>{$error}</li>";
- }
- $output .= "</ul>";
- $output .= "</div>";
- }
- return $output;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement