Validates an array containing rgb-colors. The array needs to contain
three integer-values, each between 0 and 255 to be valid

@param integer[] $rgbArr the rgb-values
@return boolean true if ok, otherwise false
14073
public static function validateRgbColor($rgbArr)
	{
		if (count($rgbArr) != 3) return false;
		foreach ($rgbArr as $val) {
			if ($val < 0 || $val > 255) return false;
		}
		return true;
	}
1164167
public static function isValidArray($arr)
    {
        if (!is_array($arr) || empty($arr) || count($arr) < 1) {
            return false;
        }

        return true;
    }
1102975
private function createImageColor($colorArray)
	{
		$r = $colorArray['r'];
		$g = $colorArray['g'];
		$b = $colorArray['b'];

		return imagecolorallocate($this->imageResized, $r, $g, $b);
	}
1246312
protected function validate()
    {
        foreach ($this->_requiredAttr as $attr) {
            if (is_array($attr)) {
                $valid = false;
                foreach ($attr as $sub) {
                    if (!is_null($this->$sub)) {
                        $valid = true;
                        break;
                    }
                }
                if (!$valid) {
                    return false;
                }
            } elseif (is_null($this->$attr)) {
                return false;
            }
        }
        return true;
    }
75778
public function validate($validator)
    {
        $this->value = trim($this->value);

        $pattern = '^[a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$';

        // Escape delimiter characters.
        $safePattern = str_replace('/', '\\/', $pattern);

        if ($this->value && !preg_match('/' . $safePattern . '/i', $this->value)) {
            $validator->validationError(
                $this->name,
                _t('SilverStripe\\Forms\\EmailField.VALIDATION', 'Please enter an email address'),
                'validation'
            );

            return false;
        }

        return true;
    }
542756
public static function Rgb2Hex( $r, int $g = -1, int $b = -1 )
   {

      if ( \is_array( $r ) )
      {

         if ( \count( $r ) != 3 )
         {
            return false;
         }

         \array_change_key_case( $r, \CASE_LOWER );

         if ( isset( $r[ 'r' ] ) && isset( $r[ 'g' ] ) && isset( $r[ 'b' ] ) )
         {
            $g = $r[ 'g' ];
            $b = $r[ 'b' ];
            $r = $r[ 'r' ];
         }
         else if ( isset( $r[ 'red' ] ) && isset( $r[ 'green' ] ) && isset( $r[ 'blue' ] ) )
         {
            $g = $r[ 'green' ];
            $b = $r[ 'blue' ];
            $r = $r[ 'red' ];
         }
         else
         {
            $rgb = $r;
            list( $r, $g, $b ) = $rgb;
         }

      }
      else if ( \preg_match( '~^(rgb\s*\()?(\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)?$~', (string) $r, $m ) )
      {

         list( $ignore, $r, $g, $b ) = $m;
         if ( ! empty( $ignore ) )
         {
            unset( $ignore );
         }

      }
      else if ( ! \is_int( $r ) )
      {

         return false;

      }
      $r1 = \intval( $r );
      $g1 = \intval( $g );
      $b1 = \intval( $b );
      $r  = \dechex( $r1 < 0 ? 0 : ( $r1 > 255 ? 255 : $r1 ) );
      $g  = \dechex( $g1 < 0 ? 0 : ( $g1 > 255 ? 255 : $g1 ) );
      $b  = \dechex( $b1 < 0 ? 0 : ( $b1 > 255 ? 255 : $b1 ) );

      return \sprintf( '#%02s%02s%02s', $r, $g, $b );

   }
466001
public function validate($validator)
    {
        $valid = true;
        foreach ($this->children as $child) {
            /** @var FormField $child */
            $valid = ($child && $child->validate($validator) && $valid);
        }
        return $valid;
    }
1354062
public function validate(&$arr)
  {
    if (count($this->list) == 0) {
      return true;
    }

    $ok = true;  

    foreach ($this->list as $key => $value) {
      $list = explode('.', $value);
      $ok = $ok && $this->walker($list, $arr);
    }

    return $ok;
  }
1049270
function(rgbaStr) {
            // lazy create the regex
            if(!this.rgbaRegex) {
                this.rgbaRegex = /^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,[\s\d.]+\)\s*$/;
            }
            var colorComponents = this.rgbaRegex.exec(rgbaStr);
            if(!colorComponents) {
                return rgbaStr;
            }
            return ("rgb(" + colorComponents[1] + ", " + colorComponents[2] + ", " + colorComponents[3] + ")");
        }
1227862
public static function Color2Rgb( $colorDefinition )
   {

      if ( \is_array( $colorDefinition ) )
      {
         if ( \count( $colorDefinition ) > 2 && \count( $colorDefinition ) < 5 )
         {
            return $colorDefinition;
         }
         throw new ArgumentError(
            'colorDefinition',
            $colorDefinition,
            'Drawing',
            'A (a)rgb(a) array with 3-4 Elements is required!'
         );
      }

      if ( static::IsHexFormat( $colorDefinition ) )
      {
         return static::Hex2Rgb( $colorDefinition );
      }

      $uc = \strtolower( $colorDefinition );

      if ( isset( static::$ColornameRGB[ $uc ] ) )
      {
         return static::$ColornameRGB[ $uc ];
      }

      if ( false !== ( $hex = static::Rgb2Hex( $colorDefinition ) ) )
      {
         return static::Hex2Rgb( $hex );
      }

      return false;

   }
29281
public static function arrayContainsArrayItems($arr)
    {
        if (!self::isValidArray($arr)) {
            return false;
        }

        foreach ($arr as $item) {
            if (self::isValidArray($item)) {
                return true;
            }
        }

        return false;
    }
986068
function COLOR_VALIDATOR(v) {
  v = (v || '').toString()

  if (v.match(/^#[0-9a-fA-F]{6}$/)) {
    return {value: v}
  }

  if (v.match(/^#[0-9a-fA-F]{3}$/)) {
    return {
      value: '#' + v[1] + v[1] + v[2] + v[2] + v[3] + v[3],
      reason: function reason(k, v, result) {
        return 'NOTE: property value `' + v + '` is autofixed to `' + result + '`'
      }
    }
  }

  if (EXTENDED_COLOR_KEYWORDS[v]) {
    return {
      value: EXTENDED_COLOR_KEYWORDS[v],
      reason: function reason(k, v, result) {
        return 'NOTE: property value `' + v + '` is autofixed to `' + result + '`'
      }
    }
  }

  var arrColor, r, g, b, a
  var RGB_REGEXP = /^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/gi
  var RGBA_REGEXP = /^rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d*\.?\d+)\s*\)$/gi
  if (arrColor = RGB_REGEXP.exec(v)) {
    r = parseInt(arrColor[1])
    g = parseInt(arrColor[2])
    b = parseInt(arrColor[3])
    if (r >= 0 && r <= 255 && g >= 0 && g <= 255 && b >= 0 && b <= 255) {
      return {value: 'rgb(' + [r, g, b].join(',') + ')'}
    }
  }
  if (arrColor = RGBA_REGEXP.exec(v)) {
    r = parseInt(arrColor[1])
    g = parseInt(arrColor[2])
    b = parseInt(arrColor[3])
    a = parseFloat(arrColor[4])
    if (r >= 0 && r <= 255 && g >= 0 && g <= 255 && b >= 0 && b <= 255 && a >= 0 && a <= 1) {
      return {value: 'rgba(' + [r, g, b, a].join(',') + ')'}
    }
  }
  if (v === 'transparent') {
    return {value: 'rgba(0,0,0,0)'}
  }

  return {
    value: null,
    reason: function reason(k, v, result) {
      return 'ERROR: property value `' + v + '` is not valid for `' + util.camelCaseToHyphened(k) + '`'
    }
  }
}
894488
protected function validate($code)
    {
        $color = str_replace(['rgba', '(', ')', ' '], '', DefinedColor::find($code, 1));
        if (substr_count($color, ',') === 2) {
            $color = "{$color},1.0";
        }
        $color = $this->fixPrecision($color);
        if (preg_match($this->validationRules(), $color, $matches)) {
            if ($matches[1] > 255 || $matches[2] > 255 || $matches[3] > 255 || $matches[4] > 1) {
                return false;
            }
            return $color;
        }
        return false;
    }
997535
protected static function _colorRGB($sColor) {
		$sError = 'unknown color "'.$sColor.'"';
		$sColor = strtolower($sColor);

		$sColorOrig = $sColor;

		$sColor = preg_replace('/^#/', '', $sColor);
		if (strlen($sColor) > 6 || !preg_match('#^[0-9a-f]+$#', $sColor)) {
			throw new TangoException($sError);
		}

		switch (strlen($sColor)) {
			case 3:
				$lColor = str_split($sColor, 1);
				$sColor = $lColor[0] . $lColor[0]
					. $lColor[1] . $lColor[1]
					. $lColor[2] . $lColor[2];
				break;
			case 6:
				break;
			default:
				throw new TangoException($sError);
				break;
		}

		$lColor = str_split($sColor, 2);
		$lColor = array_map('hexdec', $lColor);

		return $lColor;
	}
983594
public function validate($arr)
    {
        $returnValue = new ValidatorResult();
        $this->currentNode = 'root';

        try {
            $this->validateSchemaBeginsWithRootKey(new CustomArrayObject($this->schema));

            if ($this->strictMode) {
                $this->validateExcessiveKeysAbsent(new CustomArrayObject($this->schema['root']), $arr);
            }

            $this->validateNode('root', new CustomArrayObject($this->schema), $arr);
        } catch (Exception $exc) {
            $this->getLogger()->error($exc->getMessage());

            $returnValue->setError($exc->getCode(), $this->getCurrentNode(), $exc->getMessage());
            $returnValue->setLog($this->getLogger()->getLog());
        }

        return $returnValue;
    }
1007677
private static function _readRGB($rgb)
	{
		// offset: 0; size 1; Red component
		$r = ord($rgb{0});

		// offset: 1; size: 1; Green component
		$g = ord($rgb{1});

		// offset: 2; size: 1; Blue component
		$b = ord($rgb{2});

		// HEX notation, e.g. 'FF00FC'
		$rgb = sprintf('%02X%02X%02X', $r, $g, $b);

		return array('rgb' => $rgb);
	}
777522
def check_color(c):
    

    c = asarray(c)
    if c.ndim == 1:
        c = c.flatten()
        c = c[newaxis, :]
        if c.shape[1] != 3:
            raise Exception("Color must have three values per point")
    elif c.ndim == 2:
        if c.shape[1] != 3:
            raise Exception("Color array must have three values per point")
    return c