Overview

Namespaces

  • Jyxo
    • Beholder
      • TestCase
    • Gettext
      • Parser
    • Input
      • Chain
      • Filter
      • Validator
    • Mail
      • Email
        • Attachment
      • Parser
      • Sender
    • Rpc
      • Json
      • Xml
    • Shell
    • Spl
    • Svn
    • Time
    • Webdav
  • PHP

Classes

  • AbstractValidator
  • Callback
  • Equals
  • InArray
  • IsArray
  • IsBankAccountNumber
  • IsBirthNumber
  • IsCompanyId
  • IsCountryCode
  • IsDate
  • IsDateTime
  • IsEmail
  • IsIban
  • IsInt
  • IsIpV4
  • IsIpV6
  • IsNumeric
  • IsPhone
  • IsTaxId
  • IsUrl
  • IsZipCode
  • LessThan
  • NotEmpty
  • Regex
  • StringLengthBetween
  • StringLengthGreaterThan
  • StringLengthLessThan
  • Upload

Interfaces

  • ErrorMessage

Exceptions

  • Exception
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
 1: <?php
 2: 
 3: /**
 4:  * Jyxo PHP Library
 5:  *
 6:  * LICENSE
 7:  *
 8:  * This source file is subject to the new BSD license that is bundled
 9:  * with this package in the file license.txt.
10:  * It is also available through the world-wide-web at this URL:
11:  * https://github.com/jyxo/php/blob/master/license.txt
12:  */
13: 
14: namespace Jyxo\Input\Validator;
15: 
16: /**
17:  * Validates a URL.
18:  *
19:  * @category Jyxo
20:  * @package Jyxo\Input
21:  * @subpackage Validator
22:  * @copyright Copyright (c) 2005-2011 Jyxo, s.r.o.
23:  * @license https://github.com/jyxo/php/blob/master/license.txt
24:  * @author Jaroslav HanslĂ­k
25:  */
26: class IsUrl extends \Jyxo\Input\Validator\AbstractValidator
27: {
28:     /**
29:      * Validates a value.
30:      *
31:      * @param mixed $value Input value
32:      * @return boolean
33:      */
34:     public function isValid($value)
35:     {
36:         $patternGenericTld = '(?:aero|biz|cat|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|net|org|pro|tel|travel|asia|post|geo)';
37:         $patternTld = '(?-i:' . $patternGenericTld . '|[a-z]{2})';
38:         $patternDomain = '(?:(?:[a-z]|[a-z0-9](?:[-a-z0-9]{0,61}[a-z0-9]))[.])*(?:[a-z0-9](?:[-a-z0-9]{0,61}[a-z0-9])[.]' . $patternTld . ')';
39: 
40:         // protocol://user:password@
41:         $patternUrl = '(?:(?:http|ftp)s?://(?:[\S]+(?:[:][\S]*)?@)?)?';
42:         // domain.tld
43:         $patternUrl .= '(?:' . $patternDomain . ')';
44:         // :port/path/file.extension
45:         $patternUrl .= '(?::[0-9]+)?(?:(?:/+[-\w\pL\pN\~.:!%]+)*(?:/|[.][a-z0-9]{2,4})?)?';
46:         // ?query#hash
47:         $patternUrl .= '(?:[?&][\]\[-\w\pL\pN.,?!\~%#@&;:/\'\=+]*)?(?:#[\]\[-\w\pL\pN.,?!\~%@&;:/\'\=+]*)?';
48: 
49:         if (!preg_match('~^' . $patternUrl . '$~i', (string) $value)) {
50:             return false;
51:         }
52: 
53:         return true;
54:     }
55: }
56: 
Jyxo PHP Library API documentation generated by ApiGen 2.3.0