for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php /** MicroUrlValidator */
namespace Micro\Validator;
use Micro\Form\IFormModel;
/**
* UrlValidator class file.
*
* @author Oleg Lunegov <[email protected]>
* @link https://github.com/linpax/microphp-framework
* @copyright Copyright (c) 2013 Oleg Lunegov
* @license https://github.com/linpax/microphp-framework/blob/master/LICENSE
* @package Micro
* @subpackage Validator
* @version 1.0
* @since 1.0
*/
class UrlValidator extends BaseValidator
{
* @inheritdoc
public function validate(IFormModel $model)
foreach ($this->elements AS $element) {
if (!$model->checkAttributeExists($element)) {
$this->errors[] = 'Parameter '.$element.' not defined in class '.get_class($model);
return false;
}
if (filter_var($model->$element, FILTER_VALIDATE_URL) === false) {
$this->errors[] = 'Parameter '.$element.' is not a valid URL address';
return true;
public function client(IFormModel $model)
$javaScript = 'if (/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/.test(this.value'.
') != true) { e.preventDefault(); this.focus(); alert(\'Value is not a URL\'); }';
return $javaScript;