字串檢查.

@author		https://www.ecpay.com.tw
@category	Validate
@param		string	$Name		參數名稱
@param		string	$Value		參數內容
@param		int	$MaxLength	參數最大長度
@param		bool	$AllowEmpty	是否允許空值
@version		1.0.1012
766995
private function ValidateString($Name, $Value, $MaxLength = 1, $AllowEmpty = false)
        {
            if (empty($Value)) {
                // 是否允許空值
                $this->IsAllowEmpty($Name, $AllowEmpty);
            } else {
                // 長度檢查
                $this->IsOverLength($Name, $this->StringLength($Value, $this->Encode), $MaxLength);
            }
        }
359877
public List<MultipartFile> validateFiles(List<MultipartFile> files, long maxLength, String[] allowExtName) {

        List<MultipartFile> retFiles = new ArrayList<MultipartFile>();

        for (MultipartFile multipartFile : files) {

            try {

                this.validateFile(multipartFile, maxLength, allowExtName);
                retFiles.add(multipartFile);

            } catch (Exception e) {

                LOG.warn(e.toString());
            }
        }

        return retFiles;
    }
886709
def _validate_maxlength(self, max_length, field, value):
        
        if isinstance(value, Iterable) and len(value) > max_length:
            self._error(field, errors.MAX_LENGTH, len(value))
121162
private static boolean isValid(String name) {
    return !name.isEmpty() && name.length() <= MAX_LENGTH && StringUtils.isPrintableString(name);
  }
134477
public static function maxLength($value, $param)
    {
        $length = is_array($value) ? count($value) : mb_strlen($value);

        return $length <= $param;
    }
21246
public static function username(string $value, int $minLength = 5, int $maxLength = 20):bool
    {
        return (bool)preg_match("!^[_a-zA-Z0-9\\x{4e00}-\\x{9fa5}]{" . $minLength . "," . $maxLength . "}$!u", $value);
    }
1199182
protected function validateNumericArray($name, $value)
    {
        if (!is_array($value) || empty($value) || !$this->isNumeric($value)) {
            throw new \Exception($name . ' must be a non-empty numeric array.');
        }
    }
1022204
protected function setNonEmptyAttribute(\DomElement $element, string $name, string $value = null) : void
    {
        if (! is_null($value)) {
            $element->setAttribute($name, $value);
        }
    }
178504
protected function link($name, $value){
        //Si no se completo no se valida
        if(! $this->isComplete($value)){
            return TRUE;
        }
        if(! filter_var($value, FILTER_VALIDATE_URL)){
            $this->add_message($name, 'link');
            return FALSE;
        }
        return TRUE;
    }
1047956
public function addChildWithCDATA($name, $value = null, $allowNull = true)
    {
        if (!$allowNull && $value === null) {
            return null;
        }

        $newChild = $this->addChild($name);
        if ($value === Shopgate_Model_AbstractExport::SET_EMPTY) {
            $newChild->addAttribute('forceEmpty', '1');

            return $newChild;
        }

        $value = preg_replace(self::PATTERN_INVALID_CHARS, '', $value);
        if ($newChild !== null && $value != '') {
            $node  = dom_import_simplexml($newChild);
            $cData = $node->ownerDocument->createCDATASection($value);
            if ($cData !== null & $cData !== false) {
                $node->appendChild($cData);
            }
        }

        return $newChild;
    }
1009955
public void expectMax(String name, double maxLength, String message) {
        String value = Optional.ofNullable(get(name)).orElse("");

        if (StringUtils.isNumeric(value)) {
            if (Double.parseDouble(value) > maxLength) {
                addError(name, Optional.ofNullable(message).orElse(messages.get(Validation.MAX_KEY.name(), name, maxLength)));
            }
        } else {
            if (value.length() > maxLength) {
                addError(name, Optional.ofNullable(message).orElse(messages.get(Validation.MAX_KEY.name(), name, maxLength)));
            }
        }
    }
855475
public function validateMaxLength($value)
  {
    if (!isset($this->attr["maxlength"])) return true;

		$maxlength = trim($this->attr["maxlength"]);
    $length = strlen($value);

    if ($length > $maxlength) {
      $this->errors[] =  "\"{$this->label}\" contains {$length} characters, but it is limited to {$maxlength} characters. Please shorten the length.";
			return false;
		}

		return true;
  }
903314
protected function isAcceptLength($value)
    {
        $value = strlen(utf8_decode($value));

        if ($value < $this->min) {
            throw new ExceptionFactory('InvalidLength', [$value, 'greater', $this->min]);
        }
        else if ($value > $this->max) {
            throw new ExceptionFactory('InvalidLength', [$value, 'less', $this->max]);
        }

        return true;
    }
981101
public function not_empty($name, $value){
        if($value != NULL){
            return TRUE;
        }else{
            $this->add_message($name, 'empty_file');
            return FALSE;
        }
    }
165183
private function maxLength()
	{
		$max = mb_strlen($this->value);
		if (!$ret = $max <= $this->options->max) {
			$this->error(1);
		}

		return $ret;
	}
332654
protected function _validate($name, $value)
	{
 		switch ($name)
		{
			case 'offset':
			case 'total_items':
				// make sure it's an integer
				if ($value != intval($value))
				{
					$value = 0;
				}
				// and that it's within bounds
				$value = max(0, $value);
			break;

			// integer or string
			case 'uri_segment':
				if (is_numeric($value))
				{
					// make sure it's an integer
					if ($value != intval($value))
					{
						$value = 1;
					}
					// and that it's within bounds
					$value = max(1, $value);
				}
			break;

			// validate integer values
			case 'current_page':
			case 'per_page':
			case 'limit':
			case 'total_pages':
			case 'num_links':
				// make sure it's an integer
				if ($value != intval($value))
				{
					$value = 1;
				}
				// and that it's within bounds
				$value = max(1, $value);
			break;

			// validate booleans
			case 'show_first':
			case 'show_last':
				if ( ! is_bool($value))
				{
					$value = (bool) $value;
				}
			break;

			// validate the link offset, and adjust if needed
			case 'link_offset':
				// make sure we have a fraction between 0 and 1
				if ($value > 1)
				{
					$value = $value / 100;
				}

				// and that it's within bounds
				$value = max(0.01, min($value, 0.99));
			break;
		}

		return $value;
	}
1099276
protected function length_between($name, $value, $param){
        //Si no se completo no se valida
        if(! $this->isComplete($value)){
            return TRUE;
        }
        $params= explode('&', $param);
        $min= $params[0];
        $max= $params[1];
        if(is_string($value) || strval($value)){
            if(strlen($value) >= $min && strlen($value) <= $max){
                return TRUE;
            }else{
                $this->add_message($name, 'length_between', array('min' => $min, 'max' => $max));
                return FALSE;
            }
        }else{
            $this->add_message($name, 'is_string');
            return FALSE;
        }
    }