Implement UrlValidator

This commit is contained in:
Alexander A. Klimov 2016-02-23 13:13:06 +01:00
parent b670855f25
commit b7bdf2e8d4
1 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,41 @@
<?php
/* Icinga Web 2 | (c) 2016 Icinga Development Team | GPLv2+ */
namespace Icinga\Web\Form\Validator;
use Zend_Validate_Abstract;
/**
* Validator that checks whether a textfield doesn't contain raw double quotes
*/
class UrlValidator extends Zend_Validate_Abstract
{
/**
* Error templates
*
* @var array
*
* @see Zend_Validate_Abstract::$_messageTemplates
*/
protected $_messageTemplates = array(
'HAS_QUOTES' => 'The url must not contain raw double quotes. If you really need double quotes, use %22 instead.'
);
/**
* Validate the input value
*
* @param string $value The string to validate
*
* @return bool true if and only if the input is valid, otherwise false
*
* @see Zend_Validate_Abstract::isValid()
*/
public function isValid($value)
{
$hasQuotes = false === strpos($value, '"');
if (! $hasQuotes) {
$this->_error('HAS_QUOTES');
}
return $hasQuotes;
}
}