public static function regex($value, $pattern, $message = '')
{
if (!preg_match($pattern, $value)) {
static::reportInvalidArgument(sprintf($message ?: 'The value %s does not match the expected pattern.', static::valueToString($value)));
}
}
/** * @param string $value */ public static function create($value) { try { Assert::string($value, 'Value must be a string'); Assert::regex($value, '{^(?:.*\\d.*){6}$}', 'Value must contain 6 digits'); } catch (\InvalidArgumentException $e) { throw E::wrap($e); } return new self(preg_replace('{[^0-9]}', '', $value)); }