How can i validate a url field in zend framework. I tried the following code.
$website = $this->createElementText('website', 'Website');
$website->setOptions(
array(
'filters' => array(
'StringTrim',
'StripTags',
),
'validators' => array(
'NotEmpty',
array(
'Callback',
true,
array(
'callback' => function($value) {
// if (!strpos($value, 'http')) $value = 'http://' . $value;
return Zend_Uri::check($value);
}
),
'messages' => array(
Zend_Validate_Callback::INVALID_VALUE => 'Please enter a valid URL',
),
),
),
)
)->setErrorMessages(array('Please enter a valid URL. For e.g, http://test.com or http://www.test.com'));
$form->addElements(array($website));
But this is not accurate. For example it is not giving errors for urls like htt://www.google
How can i improve my validation.Is there any other method?