public function checkFormat($entity, $schema, $entityName)
    {
        if (!isset($schema->format)) {
            return $this;
        }

        $valid = true;
        switch ($schema->format) {
            case 'date-time':
                if (!preg_match('#^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$#', $entity)) {
                    $valid = false;
                }
                break;
            case 'date':
                if (!preg_match('#^\d{4}-\d{2}-\d{2}$#', $entity)) {
                    $valid = false;
                }
                break;
            case 'time':
                if (!preg_match('#^\d{2}:\d{2}:\d{2}$#', $entity)) {
                    $valid = false;
                }
                break;
            case 'utc-millisec':
                if ($entity < 0) {
                    $valid = false;
                }
                break;
            case 'color':
                if (!in_array($entity, array('maroon', 'red', 'orange',
                    'yellow', 'olive', 'green', 'purple', 'fuchsia', 'lime',
                    'teal', 'aqua', 'blue', 'navy', 'black', 'gray', 'silver', 'white'))) {
                    if (!preg_match('#^\#[0-9A-F]{6}$#', $entity) && !preg_match('#^\#[0-9A-F]{3}$#', $entity)) {
                        $valid = false;
                    }
                }
                break;
            case 'style':
                if (!preg_match('#(\.*?)[ ]?:[ ]?(.*?)#', $entity)) {
                    $valid = false;
                }
                break;
            case 'phone':
                if (!preg_match('#^[0-9\-+ \(\)]*$#', $entity)) {
                    $valid = false;
                }
                break;
            case 'uri':
                if (!preg_match('#^[A-Za-z0-9:/;,\-_\?&\.%\+\|\#=]*$#', $entity)) {
                    $valid = false;
                }
                break;
        }

        if (!$valid) {
            throw new ValidationException(sprintf('Value for [%s] must match format [%s]', $entityName, $schema->format));
        }

        return $this;
    }
public function checkFormat($entity, $schema, $entityName)
    {
        if (!isset($schema->format)) {
            return $this;
        }

        $valid = true;
        switch ($schema->format) {
            case 'date-time':
                if (!preg_match('#^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$#', $entity)) {
                    $valid = false;
                }
                break;
            case 'date':
                if (!preg_match('#^\d{4}-\d{2}-\d{2}$#', $entity)) {
                    $valid = false;
                }
                break;
            case 'time':
                if (!preg_match('#^\d{2}:\d{2}:\d{2}$#', $entity)) {
                    $valid = false;
                }
                break;
            case 'utc-millisec':
                if ($entity < 0) {
                    $valid = false;
                }
                break;
            case 'color':
                if (!in_array($entity, array('maroon', 'red', 'orange',
                    'yellow', 'olive', 'green', 'purple', 'fuchsia', 'lime',
                    'teal', 'aqua', 'blue', 'navy', 'black', 'gray', 'silver', 'white'))) {
                    if (!preg_match('#^\#[0-9A-F]{6}$#', $entity) && !preg_match('#^\#[0-9A-F]{3}$#', $entity)) {
                        $valid = false;
                    }
                }
                break;
            case 'style':
                if (!preg_match('#(\.*?)[ ]?:[ ]?(.*?)#', $entity)) {
                    $valid = false;
                }
                break;
            case 'phone':
                if (!preg_match('#^[0-9\-+ \(\)]*$#', $entity)) {
                    $valid = false;
                }
                break;
            case 'uri':
                if (!preg_match('#^[A-Za-z0-9:/;,\-_\?&\.%\+\|\#=]*$#', $entity)) {
                    $valid = false;
                }
                break;
        }

        if (!$valid) {
            throw new ValidationException(sprintf('Value for [%s] must match format [%s]', $entityName, $schema->format));
        }

        return $this;
    }
public function checkFormat ( $ entity , $ schema , $ entityName ) { if ( ! isset ( $ schema -> format ) ) { return $ this ; } $ valid = true ; switch ( $ schema -> format ) { case 'date-time' : if ( ! preg_match ( '#^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$#' , $ entity ) ) { $ valid = false ; } break ; case 'date' : if ( ! preg_match ( '#^\d{4}-\d{2}-\d{2}$#' , $ entity ) ) { $ valid = false ; } break ; case 'time' : if ( ! preg_match ( '#^\d{2}:\d{2}:\d{2}$#' , $ entity ) ) { $ valid = false ; } break ; case 'utc-millisec' : if ( $ entity < 0 ) { $ valid = false ; } break ; case 'color' : if ( ! in_array ( $ entity , array ( 'maroon' , 'red' , 'orange' , 'yellow' , 'olive' , 'green' , 'purple' , 'fuchsia' , 'lime' , 'teal' , 'aqua' , 'blue' , 'navy' , 'black' , 'gray' , 'silver' , 'white' ) ) ) { if ( ! preg_match ( '#^\#[0-9A-F]{6}$#' , $ entity ) && ! preg_match ( '#^\#[0-9A-F]{3}$#' , $ entity ) ) { $ valid = false ; } } break ; case 'style' : if ( ! preg_match ( '#(\.*?)[ ]?:[ ]?(.*?)#' , $ entity ) ) { $ valid = false ; } break ; case 'phone' : if ( ! preg_match ( '#^[0-9\-+ \(\)]*$#' , $ entity ) ) { $ valid = false ; } break ; case 'uri' : if ( ! preg_match ( '#^[A-Za-z0-9:/;,\-_\?&\.%\+\|\#=]*$#' , $ entity ) ) { $ valid = false ; } break ; } if ( ! $ valid ) { throw new ValidationException ( sprintf ( 'Value for [%s] must match format [%s]' , $ entityName , $ schema -> format ) ) ; } return $ this ; }
Check format restriction

@param mixed $entity
@param object $schema
@param string $entityName

@return Validator
Check format restriction