• Модуль: currency
  • Путь к файлу: ~/bitrix/modules/currency/lib/integration/iblockmoneyproperty.php
  • Класс: BitrixCurrencyIntegrationIblockMoneyProperty
  • Вызов: IblockMoneyProperty::checkFields
static function checkFields($property, $value)
{
	$result = [];
	if(empty($value['VALUE'])) return $result;
	$explode = (is_string($value['VALUE']) ? explode(self::SEPARATOR, $value['VALUE']) : []);
	$currentValue = (isset($explode[0]) && $explode[0] !==  '' ? $explode[0] : '');
	$currentCurrency = ($explode[1] ?? '');

	if(!$currentCurrency)
		return is_numeric($currentValue) ? $result : array(Loc::getMessage('CIMP_FORMAT_ERROR'));

	if(CurrencyManager::isCurrencyExist($currentCurrency))
	{
		$format = CCurrencyLang::GetFormatDescription($currentCurrency);
		$decPoint = $format['DEC_POINT'];
		$thousandsSep = $format['THOUSANDS_SEP'];
		$decimals = $format['DECIMALS'];
		$regExp = '/^d{1,3}(('.$thousandsSep.'){0,1}d{3})*(\'.$decPoint.'d{1,'.$decimals.'})?$/';
		if($thousandsSep && $decPoint)
		{
			if ($decimals > 0)
			{
				$regExp = '/^d{1,3}(('.$thousandsSep.'){0,1}d{3})*(\'.$decPoint.'d{1,'.$decimals.'})?$/';
			}
			else
			{
				$regExp = '/^d{1,3}(('.$thousandsSep.'){0,1}d{3})*$/';
			}
		}
		elseif($thousandsSep && !$decPoint)
		{
			$regExp = '/^d{1,3}(('.$thousandsSep.'){0,1}d{3})*$/';
		}
		elseif(!$thousandsSep && $decPoint)
		{
			if ($decimals > 0)
			{
				$regExp = '/^[0-9]*(\'.$decPoint.'d{1,'.$decimals.'})?$/';
			}
			else
			{
				$regExp = '/^[0-9]*$/';
			}
		}
		elseif(!$thousandsSep && !$decPoint)
		{
			$regExp = '/^[0-9]*$/';
		}
		if(!preg_match($regExp, $currentValue))
		{
			$result[] = Loc::getMessage('CIMP_FORMAT_ERROR');
		}
	}
	else
	{
		$result[] = Loc::getMessage('CIMP_FORMAT_ERROR');
	}

	return $result;
}