Source of file TwocharsValidator.php

Size: 1,320 Bytes - Last Modified: 2016-05-18T03:08:27+02:00

buildproject/core/module_system/system/validators/TwocharsValidator.php

1234567891011121314151617181920212223242526272829303132333435363738394041424344
<?php
/*"******************************************************************************************************
*   (c) 2007-2016 by Kajona, www.kajona.de                                                              *
*       Published under the GNU LGPL v2.1, see /system/licence_lgpl.txt                                 *
*-------------------------------------------------------------------------------------------------------*
*	$Id$                                   *
********************************************************************************************************/

namespace Kajona\System\System\Validators;

use Kajona\System\System\ValidatorInterface;


/**
 * A simple validator to validate is a string has a length of exactly two chars
 * By default, the string must contain a single char, the max length is unlimited.
 *
 * @author sidler@mulchprod.de
 * @since 4.0
 * @package module_system
 */
class TwocharsValidator implements ValidatorInterface
{

    /**
     * Validates the passed chunk of data.
     * In most cases, this'll be a string-object.
     *
     * @param string $objValue
     *
     * @return bool
     */
    public function validate($objValue)
    {

        if (!is_string($objValue)) {
            return false;
        }

        return uniStrlen($objValue) === 2;
    }

}