/** * This checks if the specified text is a valid HTTP url. It should start with http:// and it should have at * least one dot in there. * * @param $val The value to test. * @param $opts (not required) * @param $formelement (not required) */ function httpurl($val, $opts = array(), $formelement = null) { // Return true if empty if (empty($val)) { return true; } // Convert to lowercase and trim $val = strtolower(trim($val)); // Check lenght if (strlen($val) > 255) { return false; } // Add http:// if needed if (substr($val, 0, 7) != 'http://' && substr($val, 0, 8) != 'https://') { $val = 'http://' . $val; } // Compute expression $expression = '/^(https?:\\/\\/)' . '?(([0-9a-z_!~*\'().&=+$%-]+:)?[0-9a-z_!~*\'().&=+$%-]+@)?' . '(([0-9]{1,3}\\.){3}[0-9]{1,3}' . '|' . '([0-9a-z_!~*\'()-]+\\.)*' . '([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\\.' . '[a-z]{2,6}' . '|' . 'localhost)' . '(:[0-9]{1,5})?' . '((\\/?)|' . '(\\/[0-9a-z_!~*\'().;?:@&=+$,%#-]+)+\\/?)$/'; return YDValidateRules::regex($val, $expression); }
/** * This checks if the array with hours and minutes, days, months and years elements is a valid datetime or not. * * @param $val The value to test. * @param $opts (not required) */ function datetime($val, $opts = '') { return YDValidateRules::date($val) && YDValidateRules::time($val); }
/** * This method checks if a username and password are valid * * @param $username User username * @param $password User password (if password length is smaller than 32 we must md5 it, password form elements must have max 31) * * @returns ARRAY with user attributes, FALSE otherwise */ function valid($username = '', $password = '') { // test username and password if (!YDValidateRules::alphanumeric($username)) { return false; } if (!YDValidateRules::maxlength($username, 100)) { return false; } if (!YDValidateRules::alphanumeric($password)) { return false; } if (!YDValidateRules::maxlength($password, 32)) { return false; } // reset values $this->resetAll(); // set username $this->set('username', $username); // if password is not in md5 format we must set it if (strlen($password) != 32) { $password = md5($password); } // set password $this->set('password', $password); // check user state based on state and/or user login schedule $now = YDStringUtil::formatDate(time(), 'datetimesql'); // relation with userobject $this->load('ydcmuserobject'); $this->where('(state = 1 OR (state = 2 AND login_start < "' . $now . '" AND login_end > "' . $now . '"))'); // test if we get just one user if ($this->find('ydcmuserobject') != 1) { return false; } return $this->getValues(); }
/** * This checks if the array with hours and minutes, days, months and years elements is a valid datetime or not. * * @param $val The value to test. * @param $opts (not required) * * @deprecated The date rule should be used instead. */ function datetime($val, $opts = array()) { return YDValidateRules::date($val, $opts); }
/** * This rule checks if a file upload had the filename based on a regular expression. * * @param $val The value to test. * @param $opts The regex to which the filename should match. */ function filename($val, $opts) { return YDValidateRules::regex($val['name'], $opts); }