check the VAT identification number, country version for Ireland.

@param pvatId vat id to check
@return true if checksum is ok
196539
private boolean checkIeVatId(final String pvatId) {
    final char checkSum = pvatId.charAt(9);
    String vatId = pvatId;
    if (pvatId.charAt(3) >= 'A' && pvatId.charAt(3) <= 'Z') {
      // old id, can be transfered to new form
      vatId = pvatId.substring(0, 2) + "0" + pvatId.substring(4, 9) + pvatId.substring(2, 3)
          + pvatId.substring(9);
    }
    final int sum = (vatId.charAt(2) - '0') * 8 + (vatId.charAt(3) - '0') * 7
        + (vatId.charAt(4) - '0') * 6 + (vatId.charAt(5) - '0') * 5 + (vatId.charAt(6) - '0') * 4
        + (vatId.charAt(7) - '0') * 3 + (vatId.charAt(8) - '0') * 2;
    final int calculatedCheckSum = sum % 23;
    final char calculatedCheckSumCharIe;
    if (calculatedCheckSum == 0) {
      calculatedCheckSumCharIe = 'W';
    } else {
      calculatedCheckSumCharIe = (char) ('A' + calculatedCheckSum - 1);
    }
    return checkSum == calculatedCheckSumCharIe;
  }
245084
@Override
    public boolean matchesIndexValue(int v) {
        if (pattern.length() == 0) {
            return true;
        }
        int c = UTF16.charAt(pattern, 0);
        UnicodeMatcher m = data.lookupMatcher(c);
        return (m == null) ? ((c & 0xFF) == v) : m.matchesIndexValue(v);
    }
903532
public static boolean isValidRandomIdentifier( String identifier ) {
        if (identifier.length() == UUID_LENGTH) {
            // It's the right length, but see if it's a UUID ...
            try {
                UUID.fromString(identifier);
                return true;
            } catch (IllegalArgumentException e) {
                // Nope
                return false;
            }
        }
        return false;
    }
513782
@Override
  public final boolean isValid(final Object pvalue, final ConstraintValidatorContext pcontext) {
    final String valueAsString = Objects.toString(pvalue, null);
    return StringUtils.isEmpty(valueAsString)
        || countCriteriaMatches(valueAsString) >= minRules && !isBlacklist(pcontext, valueAsString)
            && !startsWithDisalowedCharacter(pcontext, valueAsString)
            && !maxRepeatCharacterExceded(pcontext, valueAsString);
  }
171383
@Override
  public final boolean isValid(final Object pvalue, final ConstraintValidatorContext pcontext) {
    final String valueAsString;
    if (ignoreWhitspaces) {
      valueAsString =
          Objects.toString(pvalue, StringUtils.EMPTY).replaceAll("\\s+", StringUtils.EMPTY);
    } else {
      valueAsString = Objects.toString(pvalue, null);
    }
    if (StringUtils.isEmpty(valueAsString)) {
      // empty field is ok
      return true;
    }
    if (valueAsString.length() != BIC_LENGTH_MIN && valueAsString.length() != BIC_LENGTH_MAX) {
      // to short or to long, but it's handled by size validator!
      return true;
    }
    if (!valueAsString.matches(BIC_REGEX)) {
      // format is wrong!
      return false;
    }
    final String countryCode = valueAsString.substring(4, 6);
    final IbanLengthDefinition validBicLength = IBAN_LENGTH_MAP.ibanLengths().get(countryCode);

    return validBicLength != null;
  }
720534
static function isValidMId( $vMId )
	{
		$bRet	= false;

		if ( is_array( $vMId ) && count( $vMId ) > 0 )
		{
			$bRet	= true;
			foreach ( $vMId as $vItem )
			{
				if ( ! CDId::getInstance()->isValidId( $vItem ) )
				{
					$bRet = false;
					break;
				}
			}
		}
		else
		{
			$bRet = CDId::getInstance()->isValidId( intval( $vMId ) );	
		}

		return $bRet;
	}
242378
private boolean checkPtVatId(final String pvatId) {
    final int checkSum = pvatId.charAt(10) - '0';
    final int sum = (pvatId.charAt(2) - '0') * 9 + (pvatId.charAt(3) - '0') * 8
        + (pvatId.charAt(4) - '0') * 7 + (pvatId.charAt(5) - '0') * 6 + (pvatId.charAt(6) - '0') * 5
        + (pvatId.charAt(7) - '0') * 4 + (pvatId.charAt(8) - '0') * 3
        + (pvatId.charAt(9) - '0') * 2;
    int calculatedCheckSum = MODULO_11 - sum % MODULO_11;
    if (calculatedCheckSum > 9) {
      calculatedCheckSum = 0;
    }
    return checkSum == calculatedCheckSum;
  }
1095280
private boolean validateEncryptionKeyData(KeyData data) {
        if (data.getIv().length != ENCRYPTIONKEYCHAINMANAGER_AES_IV_SIZE) {
            LOGGER.warning("IV does not have the expected size: " +
                    ENCRYPTIONKEYCHAINMANAGER_AES_IV_SIZE + " bytes");
            return false;
        }
        return true;
    }
565011
public static function validate($vat)
    {
        if (empty($vat) || null === $vat || '' === $vat) {
            return false;
        }

        $countryCode = substr($vat, 0, 2);
        if (false === self::isValidCountryCode($countryCode)) {
            return false;
        }

        $vat = substr($vat, 2);
        if (0 === preg_match('/^'.self::$patterns[$countryCode].'$/', $vat)) {
            return false;
        }

        return true;
    }
491460
private boolean checkNlTaxNumber(final String ptaxNumber) {
    final int checkSum = ptaxNumber.charAt(8) - '0';
    int sum = 0;
    for (int i = 0; i < ptaxNumber.length() - 1; i++) {
      sum += (ptaxNumber.charAt(i) - '0') * (9 - i);
    }
    sum -= checkSum;
    return sum % 11 == 0;
  }
534274
public boolean checkPartition(TransactionState txnState, TheHashinator hashinator) {
        if (m_isSinglePartition) {
            // can happen when a proc changes from multi-to-single after it's routed
            if (hashinator == null) {
                return false; // this will kick it back to CI for re-routing
            }

            if (m_site.getCorrespondingPartitionId() == MpInitiator.MP_INIT_PID) {
                // SP txn misrouted to MPI, possible to happen during catalog update
                throw new ExpectedProcedureException("Single-partition procedure routed to multi-partition initiator");
            }

            StoredProcedureInvocation invocation = txnState.getInvocation();
            VoltType parameterType;
            Object parameterAtIndex;

            // check if AdHoc_RO_SP or AdHoc_RW_SP
            if (m_procedure instanceof AdHocBase) {
                // ClientInterface should pre-validate this param is valid
                parameterAtIndex = invocation.getParameterAtIndex(0);
                parameterType = VoltType.get((Byte) invocation.getParameterAtIndex(1));

                if (parameterAtIndex == null && m_isReadOnly) {
                    assert (m_procedure instanceof AdHoc_RO_SP);
                    // Replicated table reads can run on any partition, skip check
                    return true;
                }

            } else {
                parameterType = m_partitionColumnType;
                parameterAtIndex = invocation.getParameterAtIndex(m_partitionColumn);
            }

            // Note that @LoadSinglepartitionTable has problems if the parititoning param
            // uses integers as bytes and isn't padded to 8b or using the right byte order.
            // Since this is not exposed to users, we're ok for now. The right fix is to probably
            // accept the right partitioning type from the user, then rewrite the params internally
            // before we initiate the proc (like adhocs).

            try {
                int partition = hashinator.getHashedPartitionForParameter(parameterType, parameterAtIndex);
                if (partition == m_site.getCorrespondingPartitionId()) {
                    return true;
                } else {
                    // Wrong partition, should restart the txn
                    if (HOST_TRACE_ENABLED) {
                        log.trace("Txn " + txnState.getInvocation().getProcName() +
                                " will be restarted");
                    }
                }
            } catch (Exception e) {
                log.warn("Unable to check partitioning of transaction " + txnState.m_spHandle, e);
            }
            return false;
        } else {
            if (!m_catProc.getEverysite() && m_site.getCorrespondingPartitionId() != MpInitiator.MP_INIT_PID) {
                log.warn("Detected MP transaction misrouted to SPI. This can happen during a schema update. " +
                        "Otherwise, it is unexpected behavior. " +
                        "Please report the following information to support@voltdb.com");
                log.warn("procedure name: " + m_catProc.getTypeName() +
                        ", site partition id: " + m_site.getCorrespondingPartitionId() +
                        ", site HSId: " + m_site.getCorrespondingHostId() + ":" + m_site.getCorrespondingSiteId() +
                        ", txnState initiatorHSId: " + CoreUtils.hsIdToString(txnState.initiatorHSId));
                if (txnState.getNotice() instanceof Iv2InitiateTaskMessage) {
                    Iv2InitiateTaskMessage initiateTaskMessage = (Iv2InitiateTaskMessage) txnState.getNotice();
                    log.warn("Iv2InitiateTaskMessage: sourceHSId: " +
                            CoreUtils.hsIdToString(initiateTaskMessage.m_sourceHSId) +
                            ", dump: " + initiateTaskMessage);
                }
                // MP txn misrouted to SPI, possible to happen during catalog update
                throw new ExpectedProcedureException("Multi-partition procedure routed to single-partition initiator");
            }

            // For n-partition transactions, we need to rehash the partitioning values and check
            // if they still hash to the assigned partitions.
            //
            // Note that when n-partition transaction runs, it's run on the MPI site, so calling
            // m_site.getCorrespondingPartitionId() will return the MPI's partition ID. We need
            // another way of getting what partitions were assigned to this transaction.
            return true;
        }
    }
864107
@Override
  public final boolean isValid(final Object pvalue, final ConstraintValidatorContext pcontext) {
    final String valueAsString = Objects.toString(pvalue, null);
    if (StringUtils.isEmpty(valueAsString)) {
      return true;
    }
    if (!StringUtils.isNumeric(valueAsString)) {
      // EAN8 must be numeric, but that's handled by digits annotation
      return true;
    }
    if (valueAsString.length() != GTIN8_LENGTH) {
      // EAN8 size is wrong, but that's handled by size annotation
      return true;
    }
    // calculate and check checksum (GTIN8/EAN8)
    return CHECK_GTIN8.isValid(valueAsString);
  }
215291
protected function validateIndividualsShort($vatNumber)
    {
        $monthBase = array_merge(range(1, 12), range(51, 62));

        $yearOfBirth = (int)substr($vatNumber, 0, 2);
        $monthOfBirth = (int)substr($vatNumber, 2, 2);
        $dayOfBirth = (int)substr($vatNumber, 4, 2);

        //validate day
        if ($dayOfBirth < 1 || $dayOfBirth > 31) {
            return false;
        }

        //validate month
        if (in_array($monthOfBirth, $monthBase) === false) {
            return false;
        };

        //validate year
        if ($yearOfBirth > 53) {
            return false;
        }

        return true;
    }
1316901
public function isValid($value = null, $context = null)
    {
        if (!is_string($value)) {
            $this->error(self::INVALID);

            return false;
        }

        $country = $this->getCountry();

        if (!array_key_exists($country, $this->vatin)) {
            if (array_key_exists($country, $context)) {
                $country = $context[$country];
            } else {
                $country = substr($value, 0, 2);
            }
        }

        if (!array_key_exists($country, $this->vatin)) {
            $this->error(self::UNSUPPORTED);

            return false;
        }

        if (!preg_match($this->vatin[$country], $value)) {
            $this->error(self::NO_MATCH);

            return false;
        }

        if (in_array($country, $this->viesCountries, true)) {
            $client = new Client(
                'http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl',
                [
                    'soap_version' => SOAP_1_1
                ]
            );

            $vatNumber = $value;

            if (strpos($vatNumber, $country) === 0) {
                $vatNumber = substr($vatNumber, strlen($country));
            }

            try {
                /** @noinspection PhpUndefinedMethodInspection */
                $response = $client->checkVat(
                    [
                        'countryCode' => $country,
                        'vatNumber'   => $vatNumber
                    ]
                );

                if (!$response->valid) {
                    $this->error(self::NO_MATCH);

                    return false;
                }
            } catch (SoapFault $e) {
                $this->error(self::NO_MATCH);

                return false;
            }
        }

        return true;
    }
666104
private boolean checkInetAddress(InetAddress inetAddress) {

        //  Check if not local host
        if (! inetAddress.getCanonicalHostName().startsWith("local")) {
            //  Check if name is not the address (???)
            if (!inetAddress.getCanonicalHostName().equalsIgnoreCase(inetAddress.getHostAddress())) {

                addresses.add(inetAddress.getHostAddress());

                //  Check if IPV 4 address
                if (isIPV4address(inetAddress.getHostAddress())) {
                    name = inetAddress.getCanonicalHostName();
                    address = inetAddress.getHostAddress();
                    //System.out.println(name+":	" + address);
                    return true;
                }
            } else if (trace)
                System.err.println(
                        "Warning: at least one getCanonicalHostName() returns " + inetAddress.getCanonicalHostName() +
                        "\n  Check files /etc/resolv.conf and /etc/nsswitch.conf ");
        }
        return false;
    }
260291
public static boolean isValidIPV4Address(String value) {

        int periods = 0;
        int i = 0;
        int length = value.length();

        if (length > 15)
            return false;
        char c = 0;
        String word = "";
        for (i = 0; i < length; i++) {
            c = value.charAt(i);
            if (c == '.') {
                periods++;
                if (periods > 3)
                    return false;
                if (word == "")
                    return false;
                if (Integer.parseInt(word) > 255)
                    return false;
                word = "";
            } else if (!(Character.isDigit(c)))
                return false;
            else {
                if (word.length() > 2)
                    return false;
                word += c;
            }
        }

        if (word == "" || Integer.parseInt(word) > 255)
            return false;
        if (periods != 3)
            return false;
        return true;
    }
455693
@Override
  public final boolean isValid(final Object pvalue, final ConstraintValidatorContext pcontext) {
    final String valueAsString = Objects.toString(pvalue, null);

    if (StringUtils.isEmpty(valueAsString)) {
      // empty field is ok
      return true;
    }
    return allowDin5008 && valueAsString.matches(PHONE_NUMBER_DIN5008) //
        || allowE123 && valueAsString.matches(PHONE_NUMBER_E123) //
        || allowUri && valueAsString.matches(PHONE_NUMBER_URI) //
        || allowMs && valueAsString.matches(PHONE_NUMBER_MS) //
        || allowCommon && valueAsString.matches(PHONE_NUMBER_COMMON);
  }