验证的字段必须为 yes, on, 1, true 这在确认「服务条款」是否同意时相当有用。
@from laravel
@param mixed $val
@return bool
353481
public static function accepted($val): bool
    {
        if (!\is_scalar($val)) {
            return false;
        }

        return false !== \stripos(Helper::IS_TRUE, '|' . $val . '|');
    }
951211
public function isSelected($val)
    {
        if ($this->isMulti()) {
            return in_array($val, $this->getValue());
        } else {
            return $val === $this->getValue();
        }
    }
1335396
protected function TryEq( $val, &$res )
	{
		$res = false;
		if ( ! $val instanceof ValueProxy ) return false;
		if ( $val->GetValueCode() != $this->GetValueCode() ) return false;

		$res = $this->Eq( $val );
		return true; // This SHOULD return true to indicate the comparison was successful
	}
603869
public static function eq($val, $expected, $strict = true): bool
    {
        return $strict ? $val === $expected : $val == $expected;
    }
486958
protected function _validate_bool($value)
    {
        $trueValues = ['1', 'true'];
        $falseValues = ['0', 'false'];

        if (in_array($value, $trueValues, true)) {
            return true;
        } elseif (in_array($value, $falseValues, true)) {
            return false;
        } else {
            return null;
        }
    }
1329
protected function validateCastValue($val)
    {
        if (isset($this->descriptor()->bareNumber) && $this->descriptor()->bareNumber === false) {
            return mb_ereg_replace('((^\D*)|(\D*$))', '', $val);
        }
        $isPercent = false;
        if (is_string($val)) {
            if (substr($val, -1) == '%') {
                $val = rtrim($val, '%');
                $isPercent = true;
            }
            if (isset($this->descriptor()->groupChar)) {
                $val = str_replace($this->descriptor()->groupChar, '', $val);
            }
            if (isset($this->descriptor()->decimalChar) && $this->descriptor()->decimalChar != '.') {
                $val = str_replace($this->descriptor()->decimalChar, '.', $val);
            }
        }
        if (!is_numeric($val)) {
            throw $this->getValidationException('value must be numeric', $val);
        } else {
            $val = (float) $val;
            if ($isPercent) {
                $val = $val / 100;
            }

            return $val;
        }
    }
645416
protected function Eq( $val )
	{
		$result = $this->_value == $val->getValue();

		if ( $result ||
			 is_infinite( $this->_value ) ||
			 is_nan( $this->_value ) ||
			 is_infinite( $val->getValue() ) ||
			 is_nan( $val->getValue() ) )
		{
			return $result;
		}

		$a = $this->_value;
		$b = $val->getValue();
		$limit = pow( 2, 31 );

		if ( abs( $a ) < $limit && abs( $b ) < $limit )
		{
			return $a == $b;
		}

		$expectedDecimal = DecimalValue::FromFloat( $a, false );
		$actualDecimal   = DecimalValue::FromFloat( $b, false );

		$expectedDecimalLength = $expectedDecimal->getIsDecimal() ? strlen( $expectedDecimal->getDecimalPart() ) : 0;
		$actualDecimalLength = $actualDecimal->getIsDecimal() ? strlen( $actualDecimal->getDecimalPart() ) : 0;

		$expectedDigitsLength = strlen( $expectedDecimal->getIntegerPart() );
		$actualDigitsLength = strlen( $actualDecimal->getIntegerPart() );

		// Make sure they have the same number of decimals
		if ( $expectedDecimalLength != $actualDecimalLength )
		{
			if ( $expectedDecimalLength > $actualDecimalLength )
			{
				$expectedDecimal = $expectedDecimal->getRound( $actualDecimalLength );
			}
			else
			{
				$actualDecimal = $actualDecimal->getRound( $expectedDecimalLength );
			}
		}

		if ( ! $expectedDecimal->getIsDecimal() && $expectedDigitsLength == $actualDigitsLength )
		{
			// Make sure they are the same length after removing trailing zeros. This will required when
			// the values are say 1.23E6 (which will be decimal 123000) and 1.234E6 (123400).  OK these are
			// simplified examples.  A concrete example is 1.234567890123456E38 and 1.2345678901235E38
			$expectedDigits = rtrim( $expectedDecimal->getIntegerPart(), "0" );
			if ( strlen( $expectedDigits ) == 0 ) $expectedDigits = "0";
			$actualDigits = rtrim( $actualDecimal->getIntegerPart(), "0" );
			if ( strlen( $actualDigits ) == 0 ) $actualDigits = "0";

			if ( strlen( $expectedDigits ) > strlen( $actualDigits ) )
			{
				$expectedDecimal = DecimalValue::FromValue( $expectedDigits )->getRound( strlen( $actualDigits ) - strlen( $expectedDigits ) );
				$factor = DecimalValue::FromValue( 10 )->Pow( $actualDigitsLength - strlen( $expectedDigits ) );
				$expectedDecimal = $expectedDecimal->Mul( $factor );
			}
			else if ( strlen( $expectedDigits ) < strlen( $actualDigits ) )
			{
				$actualDecimal = DecimalValue::FromValue( $actualDigits )->getRound( strlen( $expectedDigits ) - strlen( $actualDigits ), PHP_ROUND_HALF_DOWN );
				$factor = DecimalValue::FromValue( 10 )->Pow( $expectedDigitsLength - strlen( $actualDigits ) );
				$actualDecimal = $actualDecimal->Mul( $factor );
			}
		}
		else
		{
			// If the digits are not the same length ???
		}

		$result = $expectedDecimal->Equals( $actualDecimal );

		return $result;
	}
935001
public function get($val)
    {
        // If we already have the code, just return that
        if (is_numeric($val)) {
            return $val;
        }

        if (array_key_exists($val, $this->colors)) {
            return $this->colors[$val];
        }

        return null;
    }
1071884
public static function isPrime($val = null)
    {
        if (is_null($val)) {
            return null;
        }
        if (
            ($val<=1) ||
            ($val>2 && ($val%2)===0)
        ) {
            return false;
        }
        for ($i=2;$i<$val;$i++) {
            if (($val%$i)===0) {
                return false;
            }
        }
        return true;
    }
1267424
protected function TryGt( $val, &$res )
	{
	    $res = false;
	    if ( $val->GetValueCode() != DayTimeDurationProxyFactory::Code )
	        return false;

	    $res =  $this->_value->CompareTo( $val->getValue() ) > 0;
	    return true;
	}
559662
public static function max($val, $max)
	{
	    if (is_array($max)) {
	        if (!isset($max['max'])) {
	            throw new \InvalidArgumentException('The $max argument must have "max" key');
	        }
	        $max = $max['max'];
	    }

	    return $val <= $max;
	}
786648
public static function getCode($val)
    {
        if (self::$_languageFlip === array()) {
            self::$_languageFlip = array_flip(self::$_languages);
        }
        if (array_key_exists($val, self::$_languageFlip)) {
            return strtolower(self::$_languageFlip[$val]);
        }
        return null;
    }
981744
public static function strList($val): bool
    {
        if (!$val || !\is_array($val)) {
            return false;
        }

        $lastK = -1;

        /** @var array $val */
        foreach ($val as $k => $v) {
            if (!\is_int($k) || $k !== $lastK + 1) {
                return false;
            }

            if (!\is_string($v)) {
                return false;
            }

            $lastK = $k;
        }

        return true;
    }
513025
private static function boolval($value)
    {
        if (is_numeric($value)) {
            $value = (float) $value > 0;
        } elseif (is_string($value)) {
            $value = 'false' !== $value;
        }

        return is_bool($value) ? $value : false;
    }
1251240
public function boolToBinary($val)
    {
        $saved_object_count = $this->writtenObjectCount++;
        $this->objectTable[$saved_object_count] = $val ? "\x9" : "\x8"; // 0x9 is 1001, type indicator for true; 0x8 is 1000, type indicator for false
        return $saved_object_count;
    }
133998
function findone($key,$val) {
		return ($data=$this->find($key,$val))?$data[0]:FALSE;
	}
1020301
public function setValue($val)
    {

        // Fuzzy matching through strtotime() to support a wider range of times,
        // e.g. 11am. This means that validate() might not fire.
        // Note: Time formats are assumed to be less ambiguous than dates across locales.
        if ($this->getConfig('use_strtotime') && !empty($val)) {
            if ($parsedTimestamp = strtotime($val)) {
                $parsedObj = new Zend_Date($parsedTimestamp, Zend_Date::TIMESTAMP);
                $val = $parsedObj->get($this->getConfig('timeformat'));
                unset($parsedObj);
            }
        }

        if (empty($val)) {
            $this->value = null;
            $this->valueObj = null;
        }
        // load ISO time from database (usually through Form->loadDataForm())
        // Requires exact format to prevent false positives from locale specific times
        else if ($this->valueObj = $this->parseTime($val, $this->getConfig('datavalueformat'), null, true)) {
            $this->value = $this->valueObj->get($this->getConfig('timeformat'));
        }
        // Set in current locale (as string)
        else if ($this->valueObj = $this->parseTime($val, $this->getConfig('timeformat'), $this->locale)) {
            $this->value = $this->valueObj->get($this->getConfig('timeformat'));
        }
        // Fallback: Set incorrect value so validate() can pick it up
        elseif (is_string($val)) {
            $this->value = $val;
            $this->valueObj = null;
        } else {
            $this->value = null;
            $this->valueObj = null;
        }

        return $this;
    }