我使用 Zend\Validator\Hostname 来验证包含 url 的输入字符串。问题是它只接受 mydomain.com 类型的 URL,而不接受 http:// 或 https:// 协议前缀。实现所需行为的最佳方法是什么?
$inputFilter->add($factory->createInput(array(
'name' => 'shop_link',
'required' => false,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 1,
'max' => 100,
),
),
array(
'name' => 'Hostname',
'options' => array(
'allow' => \Zend\Validator\Hostname::ALLOW_DNS, // Allow these hostnames
'useIdnCheck' => true, // Check IDN domains
'useTldCheck' => true, // Check TLD elements
'ipValidator' => null, // IP validator to use
),
),
),
)));
谢谢