Back to Opencart

File system\helper\validation.php

docs/api/source-system.helper.validation.html

4.1.0.35.0 KB
Original Source

Namespaces

Functions

| 1: | <?php | | 2: | /** | | 3: | * Validate Length | | 4: | * | | 5: | * @param string $string | | 6: | * @param int $minimum | | 7: | * @param int $maximum | | 8: | * | | 9: | * @return bool | | 10: | */ | | 11: | function oc_validate_length(string $string, int $minimum, int $maximum): bool { | | 12: | return strlen(trim($string)) >= $minimum && strlen(trim($string)) <= $maximum; | | 13: | } | | 14: | | | 15: | /** | | 16: | * Validate Email | | 17: | * | | 18: | * @param string $email | | 19: | * | | 20: | * @return bool | | 21: | */ | | 22: | function oc_validate_email(string $email): bool { | | 23: | if (oc_strrpos($email, '@') === false) { | | 24: | return false; | | 25: | } | | 26: | | | 27: | $local = oc_substr($email, 0, oc_strrpos($email, '@')); | | 28: | | | 29: | $domain = oc_substr($email, (oc_strrpos($email, '@') + 1)); | | 30: | | | 31: | $email = $local . '@' . idn_to_ascii($domain, IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46); | | 32: | | | 33: | return filter_var($email, FILTER_VALIDATE_EMAIL); | | 34: | } | | 35: | | | 36: | /** | | 37: | * Validate IP | | 38: | * | | 39: | * @param string $ip | | 40: | * | | 41: | * @return bool | | 42: | */ | | 43: | function oc_validate_ip(string $ip): bool { | | 44: | return filter_var($ip, FILTER_VALIDATE_IP); | | 45: | } | | 46: | | | 47: | /** | | 48: | * Validate URL | | 49: | * | | 50: | * @param string $filename | | 51: | * | | 52: | * @return bool | | 53: | */ | | 54: | function oc_validate_filename(string $filename): bool { | | 55: | return !preg_match('/[^a-zA-Z\p{Cyrillic}0-9.-_]+/u', $filename); | | 56: | } | | 57: | | | 58: | /** | | 59: | * Validate URL | | 60: | * | | 61: | * @param string $url | | 62: | * | | 63: | * @return bool | | 64: | */ | | 65: | function oc_validate_url(string $url): bool { | | 66: | return filter_var($url, FILTER_VALIDATE_URL); | | 67: | } | | 68: | | | 69: | /** | | 70: | * Validate SEO URL | | 71: | * | | 72: | * @param string $keyword | | 73: | * | | 74: | * @return bool | | 75: | */ | | 76: | function oc_validate_seo_url(string $keyword): bool { | | 77: | return !preg_match('/[^\p{Latin}\p{Cyrillic}\p{Greek}0-9/.-_]+/u', $keyword); | | 78: | } | | 79: | |

OpenCart API API documentation generated by ApiGen dev-master