Validate the ID number.

@param string $value The ID number.
@return true|lang_string
970883
protected function validate_idnumber($value) {
        global $DB;
        $sql = 'idnumber = :idnumber AND competencyframeworkid = :competencyframeworkid AND id <> :id';
        $params = array(
            'id' => $this->get('id'),
            'idnumber' => $value,
            'competencyframeworkid' => $this->get('competencyframeworkid')
        );
        if ($DB->record_exists_select(self::TABLE, $sql, $params)) {
            return new lang_string('idnumbertaken', 'error');
        }
        return true;
    }
365905
protected function validate(&$value)
    {
        if ($this->isString($value) && $this->isNumber($value)) {
            if (!$this->str($value)->contains('.') && !$this->str($value)->contains(',')) {
                $value = intval($value);
            }
        }

        if (!$this->isInteger($value)) {
            $this->expected('integer', gettype($value));
        }

        parent::validate($value);

        return $this;
    }
619596
public function isValid($value)
    {
        if (!is_string($value)) {
            $this->error(self::INVALID);
            return false;
        }

        $this->setValue($value);
        if (!preg_match(self::PATTERN, $value)) {
            $this->error(self::NOT_MATCH);
            return false;
        }

        if (!$this->getCurrencyList()->isAllowed($value)) {
            $this->error(self::NOT_FOUND);
        }

        return count($this->getMessages()) === 0;
    }
573210
public function cardNumber($value): bool
    {
        if (!is_string($value) || strlen($value) < 12) {
            return false;
        }

        $result = 0;
        $odd = strlen($value) % 2;
        preg_replace('/[^0-9]+/', '', $value);

        for ($i = 0; $i < strlen($value); ++$i) {
            $result += $odd
                ? $value[$i]
                : (($value[$i] * 2 > 9) ? $value[$i] * 2 - 9 : $value[$i] * 2);

            $odd = !$odd;
        }

        // Check validity.
        return ($result % 10 == 0) ? true : false;
    }
1270623
public function validTagChars($value)
    {
        $success = (bool)preg_match('/^[a-z\d\s]+$/', $value);

        return $success ?: sprintf('%s: %s', I18N_ALLOWED_CHARS, I18N_LOWERCASE_NUMBERS_SPACE);
    }
1233806
public function isValid($value)
    {
        if (!is_scalar($value) || !is_numeric($value)) {
            $this->error(self::INVALID);

            return false;
        }

        $length = strlen($value);

        if ($length < 9) {
            $this->error(self::TOO_SHORT);

            return false;
        }

        if ($length > 9) {
            $this->error(self::TOO_LONG);

            return false;
        }

        if (!preg_match($this->pattern, $value, $matches)) {
            $this->error(self::NO_MATCH);

            return false;
        }

        // no digit group can be all 0's
        /** @var array $matches */
        foreach ($matches as $match) {
            if (0 === (int) $match) {
                $this->error(self::NO_MATCH);

                return false;
            }
        }

        // invalid first digit groups 666 or 900-999
        /** @noinspection TypeUnsafeComparisonInspection */
        if ($matches[1] == 666 || $matches[1] >= 900) {
            $this->error(self::NO_MATCH);

            return false;
        }

        // invalid for advertisements
        if ($value >= 987654320 && $value <= 987654329) {
            $this->error(self::NO_MATCH);

            return false;
        }
        // handle famous instance of 1938
        /** @noinspection TypeUnsafeComparisonInspection */
        if ($value == '078051120') {
            $this->error(self::NO_MATCH);

            return false;
        }

        return true;
    }
116113
protected function validate_scaleid($value) {
        global $DB;

        // Always validate that the scale exists.
        if (!$DB->record_exists_select('scale', 'id = :id', array('id' => $value))) {
            return new lang_string('invalidscaleid', 'error');
        }

        // During update.
        if ($this->get('id')) {

            // Validate that we can only change the scale when it is not used yet.
            if ($this->beforeupdate->get('scaleid') != $value) {
                if ($this->beforeupdate->has_user_competencies()) {
                    return new lang_string('errorscalealreadyused', 'core_competency');
                }
            }

        }

        return true;
    }
711071
public function validate($value)
    {
        if (!is_numeric($value)) {
            return false;
        }

        return $value / $this->number == round($value / $this->number);
    }
649052
protected function validate(&$value)
    {
        if ($value instanceof AbstractEntity) {
            $value = $value->id;
        }
        if ($value != null && !$this->isString($value) && !$this->isNumber($value)) {
            $this->expected('string, number or AbstractEntity', gettype($value));
        }

        // Make sure it's a string even if it is a number (convert to numeric string)
        $value = '' . $value;

        parent::validate($value);

        return $this;
    }
299934
public function isValueValid($value) {
		return $value instanceof Type\MenuType || $value instanceof DataType\TextType || $value instanceof DataType\URLType;
	}
1148872
public function isValid($value)
    {
        if (!is_string($value)) {
            $this->_error(self::INVALID);
            return false;
        }

        $this->_setValue($value);
        // Check input against IP address schema
        if (preg_match('/^[0-9a-f:.]*$/i', $value) &&
            $this->_options['ip']->setTranslator($this->getTranslator())->isValid($value)) {
            if (!($this->_options['allow'] & self::ALLOW_IP)) {
                $this->_error(self::IP_ADDRESS_NOT_ALLOWED);
                return false;
            } else {
                return true;
            }
        }

        // RFC3986 3.2.2 states:
        // 
        //     The rightmost domain label of a fully qualified domain name
        //     in DNS may be followed by a single "." and should be if it is 
        //     necessary to distinguish between the complete domain name and
        //     some local domain.
        //     
        // (see ZF-6363)
        
        // Local hostnames are allowed to be partitial (ending '.')
        if ($this->_options['allow'] & self::ALLOW_LOCAL) {
            if (substr($value, -1) === '.') {
                $value = substr($value, 0, -1);
                if (substr($value, -1) === '.') {
                    // Empty hostnames (ending '..') are not allowed
                    $this->_error(self::INVALID_LOCAL_NAME);
                    return false;
                }
            }
        }

        $domainParts = explode('.', $value);

        // Prevent partitial IP V4 adresses (ending '.')
        if ((count($domainParts) == 4) && preg_match('/^[0-9.a-e:.]*$/i', $value) &&
            $this->_options['ip']->setTranslator($this->getTranslator())->isValid($value)) {
            $this->_error(self::INVALID_LOCAL_NAME);
        }

        // Check input against DNS hostname schema
        if ((count($domainParts) > 1) && (strlen($value) >= 4) && (strlen($value) <= 254)) {
            $status = false;

            $origenc = iconv_get_encoding('internal_encoding');
            iconv_set_encoding('internal_encoding', 'UTF-8');
            do {
                // First check TLD
                $matches = array();
                if (preg_match('/([^.]{2,10})$/i', end($domainParts), $matches) ||
                    (end($domainParts) == 'ایران') || (end($domainParts) == '中国') ||
                    (end($domainParts) == '公司') || (end($domainParts) == '网络')) {

                    reset($domainParts);

                    // Hostname characters are: *(label dot)(label dot label); max 254 chars
                    // label: id-prefix [*ldh{61} id-prefix]; max 63 chars
                    // id-prefix: alpha / digit
                    // ldh: alpha / digit / dash

                    // Match TLD against known list
                    $this->_tld = strtolower($matches[1]);
                    if ($this->_options['tld']) {
                        if (!in_array($this->_tld, $this->_validTlds)) {
                            $this->_error(self::UNKNOWN_TLD);
                            $status = false;
                            break;
                        }
                    }

                    /**
                     * Match against IDN hostnames
                     * Note: Keep label regex short to avoid issues with long patterns when matching IDN hostnames
                     * @see Zend_Validate_Hostname_Interface
                     */
                    $regexChars = array(0 => '/^[a-z0-9\x2d]{1,63}$/i');
                    if ($this->_options['idn'] &&  isset($this->_validIdns[strtoupper($this->_tld)])) {
                        if (is_string($this->_validIdns[strtoupper($this->_tld)])) {
                            $regexChars += include(__DIR__.'/'.$this->_validIdns[strtoupper($this->_tld)]);
                        } else {
                            $regexChars += $this->_validIdns[strtoupper($this->_tld)];
                        }
                    }

                    // Check each hostname part
                    $check = 0;
                    foreach ($domainParts as $domainPart) {
                        // Decode Punycode domainnames to IDN
                        if (strpos($domainPart, 'xn--') === 0) {
                            $domainPart = $this->decodePunycode(substr($domainPart, 4));
                            if ($domainPart === false) {
                                return false;
                            }
                        }

                        // Check dash (-) does not start, end or appear in 3rd and 4th positions
                        if ((strpos($domainPart, '-') === 0)
                            || ((strlen($domainPart) > 2) && (strpos($domainPart, '-', 2) == 2) && (strpos($domainPart, '-', 3) == 3))
                            || (strpos($domainPart, '-') === (strlen($domainPart) - 1))) {
                                $this->_error(self::INVALID_DASH);
                            $status = false;
                            break 2;
                        }

                        // Check each domain part
                        $checked = false;
                        foreach($regexChars as $regexKey => $regexChar) {
                            $status = @preg_match($regexChar, $domainPart);
                            if ($status > 0) {
                                $length = 63;
                                if (array_key_exists(strtoupper($this->_tld), $this->_idnLength)
                                    && (array_key_exists($regexKey, $this->_idnLength[strtoupper($this->_tld)]))) {
                                    $length = $this->_idnLength[strtoupper($this->_tld)];
                                }

                                if (iconv_strlen($domainPart, 'UTF-8') > $length) {
                                    $this->_error(self::INVALID_HOSTNAME);
                                } else {
                                    $checked = true;
                                    break;
                                }
                            }
                        }

                        if ($checked) {
                            ++$check;
                        }
                    }

                    // If one of the labels doesn't match, the hostname is invalid
                    if ($check !== count($domainParts)) {
                        $this->_error(self::INVALID_HOSTNAME_SCHEMA);
                        $status = false;
                    }
                } else {
                    // Hostname not long enough
                    $this->_error(self::UNDECIPHERABLE_TLD);
                    $status = false;
                }
            } while (false);

            iconv_set_encoding('internal_encoding', $origenc);
            // If the input passes as an Internet domain name, and domain names are allowed, then the hostname
            // passes validation
            if ($status && ($this->_options['allow'] & self::ALLOW_DNS)) {
                return true;
            }
        } else if ($this->_options['allow'] & self::ALLOW_DNS) {
            $this->_error(self::INVALID_HOSTNAME);
        }

        // Check for URI Syntax (RFC3986)
        if ($this->_options['allow'] & self::ALLOW_URI) {
            if (preg_match("/^([a-zA-Z0-9-._~!$&\'()*+,;=]|%[[:xdigit:]]{2}){1,254}$/i", $value)) {
                return true;
            } else {
                $this->_error(self::INVALID_URI);
            }
        }

        // Check input against local network name schema; last chance to pass validation
        $regexLocal = '/^(([a-zA-Z0-9\x2d]{1,63}\x2e)*[a-zA-Z0-9\x2d]{1,63}[\x2e]{0,1}){1,254}$/';
        $status = @preg_match($regexLocal, $value);

        // If the input passes as a local network name, and local network names are allowed, then the
        // hostname passes validation
        $allowLocal = $this->_options['allow'] & self::ALLOW_LOCAL;
        if ($status && $allowLocal) {
            return true;
        }

        // If the input does not pass as a local network name, add a message
        if (!$status) {
            $this->_error(self::INVALID_LOCAL_NAME);
        }

        // If local network names are not allowed, add a message
        if ($status && !$allowLocal) {
            $this->_error(self::LOCAL_NAME_NOT_ALLOWED);
        }

        return false;
    }
572258
public static function validate($value)
    {
        if (!is_array($value)) {
            return false;
        }
        if (!isset($value['from'])) {
            return false;
        }
        if (AddressValidator::validate($value['from']) === false) {
            return false;
        }
        if (isset($value['to']) && AddressValidator::validate($value['to']) === false && $value['to'] !== '') {
            return false;
        }
        if (isset($value['gas']) && QuantityValidator::validate($value['gas']) === false) {
            return false;
        }
        if (isset($value['gasPrice']) && QuantityValidator::validate($value['gasPrice']) === false) {
            return false;
        }
        if (isset($value['value']) && QuantityValidator::validate($value['value']) === false) {
            return false;
        }
        // if (!isset($value['data'])) {
        //     return false;
        // }
        // if (HexValidator::validate($value['data']) === false) {
        //     return false;
        // }
        if (isset($value['data']) && HexValidator::validate($value['data']) === false) {
            return false;
        }
        if (isset($value['nonce']) && QuantityValidator::validate($value['nonce']) === false) {
            return false;
        }
        return true;
    }
1288249
public function validate($value)
    {
        if (!is_numeric($value)) {
            return false;
        }
        // Convert possible strings to number
        $number = $value + 0;

        return is_double($number) || !$this->strict && is_int($number);
    }
728948
public function isValid($value)
    {
        if (!is_string($value)
            && !($value instanceof Uuid) // If instance of Uuid still does not means that is valid
        ) {
            $this->error(self::INVALID);
            return false;
        }

        $this->setValue($value);

        if (!preg_match('/^' . self::UUID_V4_PATTERN . '$/', $value)) {
            $this->error(self::NOT_UUID_V4);
            return false;
        }

        return true;
    }
466898
public function isValid($value)
    {
        if (!is_string($value)) {
            $this->_error(self::INVALID);
            return false;
        }

        $this->_setValue($value);
        if ($this->_encoding !== null) {
            $length = iconv_strlen($value, $this->_encoding);
        } else {
            $length = iconv_strlen($value);
        }

        if ($length < $this->_min) {
            $this->_error(self::TOO_SHORT);
        }

        if (null !== $this->_max && $this->_max < $length) {
            $this->_error(self::TOO_LONG);
        }

        if (count($this->_messages)) {
            return false;
        } else {
            return true;
        }
    }
718177
public function validate($value)
    {
        return is_int($value) ? Ok::unit() : Error::unit([ Error::NON_INT ]);
    }
641755
protected function validate_desca($value) {
        if ($value === null) {
            return true;
        }

        $desc = json_decode($value);
        if ($desc === null && json_last_error() !== JSON_ERROR_NONE) {
            return new lang_string('invaliddata', 'error');
        }

        return true;
    }