Assert\Assertion::regex PHP Method

regex() public static method

Assert that value matches a regex
public static regex ( mixed $value, string $pattern, string | null $message = null, string | null $propertyPath = null ) : boolean
$value mixed
$pattern string
$message string | null
$propertyPath string | null
return boolean
    public static function regex($value, $pattern, $message = null, $propertyPath = null)
    {
        static::string($value, $message, $propertyPath);
        if (!preg_match($pattern, $value)) {
            $message = sprintf($message ?: 'Value "%s" does not match expression.', static::stringify($value));
            throw static::createException($value, $message, static::INVALID_REGEX, $propertyPath, array('pattern' => $pattern));
        }
        return true;
    }

Usage Example

コード例 #1
0
ファイル: Locale.php プロジェクト: gingerpayments/ginger-php
 /**
  * @param string $value
  */
 private function __construct($value)
 {
     if (!empty($value)) {
         Guard::regex($value, '/^[a-z]{2}(_[A-Z]{2})?$/', "Locale is invalid: " . $value);
     }
     $this->value = $value;
 }
All Usage Examples Of Assert\Assertion::regex