Checks the number valiaty for the Minas Gerais state
189607
def start(st_reg_number):
    """"""
    #st_reg_number = str(st_reg_number)
    number_state_registration_first_digit = st_reg_number[0:3] + '0' + st_reg_number[3: len(st_reg_number)-2]
    weights_first_digit = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]
    wights_second_digit = [3, 2, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2]
    first_digit = st_reg_number[-2]
    second_digit = st_reg_number[-1]
    sum_first_digit = 0
    sum_second_digit = 0
    sum_result_digit = ''
    sum_end = 0

    if len(st_reg_number) != 13:

        return False

    for i in range(0, 12):

        sum_first_digit = weights_first_digit[i] * int(number_state_registration_first_digit[i])

        sum_result_digit = sum_result_digit + str(sum_first_digit)

    for i in range(0, len(sum_result_digit)):

        sum_end = sum_end + int(sum_result_digit[i])

    if sum_end % 10 == 0:

        check_digit_one = 0

    elif sum_end < 10:

        check_digit_one = 10 - sum_end

    elif sum_end > 10:

        check_digit_one = (10 - sum_end % 10)

    if str(check_digit_one) != first_digit:

        return False

    number_state_registration_second_digit = st_reg_number + str(check_digit_one)

    for i in range(0, 12):

        sum_second_digit = sum_second_digit + wights_second_digit[i] * int(number_state_registration_second_digit[i])

    check_second_digit = 11 - sum_second_digit % 11

    if sum_second_digit == 1 or sum_second_digit == 0:

        return second_digit == '0'

    else:
        return str(check_second_digit) == second_digit
464284
private function calculateCellSize()
    {
        $this->_font = ZfPdf\Font::fontWithName(ZfPdf\Font::FONT_HELVETICA);
        $i = 0;
        $larg = Array();

        foreach ($this->_arrayForm['gridfieldsconfig'] as $field => $value) {
            if ($field == 'dta_cadastro' or $field == 'dta_atualizacao') {
                $larg[$i] = 4;
            } elseif ($field == 'ind_status') {
                $larg[$i] = 2;
            } elseif ($value['type'] == 'primarykey') {
                $larg[$i] = 2;
            } else {
                $fieldName = $this->_arrayLocale->translate($field);
                $larg[$i] = $this->widthForStringUsingFontSize($fieldName, $this->_font, 8);
            }
            $i++;
        }
        /*
          foreach ($this->_arrayData as $value) {
          $i = 0;
          foreach ($value as $value2) {
          $value2 = strip_tags($value2);
          if ($larg[$i] < strlen($value2)) {
          $larg[$i] = strlen($value2);
          }
          $i++;
          }
          }
         */

        return $larg;
    }
775901
protected function gerarNossoNumero()
    {
        $numero_boleto = Util::numberFormatGeral($this->getNumero(), 15);
        $composicao = '1';
        if ($this->getCarteira() == 'SR') {
            $composicao = '2';
        }

        $carteira = $composicao . '4';
        // As 15 próximas posições no nosso número são a critério do beneficiário, utilizando o sequencial
        // Depois, calcula-se o código verificador por módulo 11
        $numero = $carteira . Util::numberFormatGeral($numero_boleto, 15);
        return $numero;
    }
1143754
public static function validate($phoneNumber, $country = null)
    {
        $phoneNumber = trim($phoneNumber);
        if (empty($phoneNumber)) {
            return false;
        }
        $country = strtoupper($country);
        $phoneUtil = PhoneNumberUtil::getInstance();
        try {
            $numberProto = $phoneUtil->parse($phoneNumber, $country);
        } catch (NumberParseException $e) {
            return false;
        }

        return $phoneUtil->isValidNumber($numberProto);
    }
452338
def start(st_reg_number):
    """"""

    divisor = 11

    weight = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]

    if len(st_reg_number) != 9 and len(st_reg_number) != 14:
        return False

    if len(st_reg_number) == 9:
        sum_total = 0
        peso = 6
        for i in range(3, len(st_reg_number)-1):
            sum_total = sum_total + int(st_reg_number[i]) * peso
            peso = peso - 1

        rest_division = sum_total % divisor
        digit = divisor - rest_division

        if digit == 10:
            digit = 0

        if digit == 11:
            digit = 1

        return digit == int(st_reg_number[len(st_reg_number)-1])

    else:
        sum_total = 0
        for i in range(len(st_reg_number)-1):
            sum_total = sum_total + int(st_reg_number[i]) * weight[i]

        rest_division = sum_total % divisor
        digit = divisor - rest_division

        if digit == 10:
            digit = 0

        if digit == 11:
            digit = 1

        return digit == int(st_reg_number[len(st_reg_number)-1])
965514
private function validateGovernment(string $vatNumber): bool
    {
        $prefix = strtoupper(substr($vatNumber, 0, 2));
        $number = (int) substr($vatNumber, 2, 3);

        // Government departments
        if ($prefix == 'GD') {
            return $number < 500;
        }

        // Health authorities
        if ($prefix == 'HA') {
            return $number > 499;
        }

        return false;
    }
117666
public static function validate($phone, $region = 'RU')
    {
        try {
            return self::phoneUtil()->isValidNumberForRegion(self::phoneUtil()->parse($phone, $region), $region);
        } catch (NumberParseException $e) {
            return false;
        }
    }
1130616
protected function validateZoneCountryState()
    {
        $field = 'zone_id';
        $value = $this->getSubmitted($field);

        if (empty($value)) {
            return null;
        }

        $label = $this->translation->text('Zone');

        if (!is_numeric($value)) {
            $this->setErrorNumeric($field, $label);
            return false;
        }

        $zone = $this->zone->get($value);

        if (empty($zone)) {
            $this->setErrorUnavailable($field, $label);
            return false;
        }

        return true;
    }
727497
function(n, countryCode){

        const number = phoneUtil.parse(n, countryCode),
            isPossibleNumber = phoneUtil.isPossibleNumber(number),
	        res = {
                input: n,
                countryCode: countryCode,
                isPossibleNumber: isPossibleNumber,
                isPossibleNumberWithReason: phoneUtil.isPossibleNumberWithReason(number)
	        };

        if(isPossibleNumber){
            res.isPossibleNumber = true;
            res.isNumberValid = phoneUtil.isValidNumber(number);
            res.countryCode = countryCode;
            res.formatted = phoneUtil.formatInOriginalFormat(number, countryCode);
            res.national = phoneUtil.format(number, PNF.NATIONAL);
            res.international = phoneUtil.format(number, PNF.INTERNATIONAL)
        }

        switch (phoneUtil.isPossibleNumberWithReason(number)){

            case PNV.IS_POSSIBLE:
                res.isPossibleNumberWithReason = 'IS_POSSIBLE';
            break;

            case PNV.INVALID_COUNTRY_CODE:
                res.isPossibleNumberWithReason = 'INVALID_COUNTRY_CODE';
            break;

            case PNV.TOO_SHORT:
                res.isPossibleNumberWithReason = 'TOO_SHORT';
            break;

            case PNV.TOO_LONG:
                res.isPossibleNumberWithReason = 'TOO_LONG';
            break;
        }

        return res;
    }
232361
private function json_validate_zipcode() 
    {
        if (!empty($this->valueJson) && is_string($this->valueJson))
        {
            $ret = @json_decode($this->valueJson, true);            
            return (json_last_error() === JSON_ERROR_NONE && 
                    isset($ret['cep']) &&
                    isset($ret['logradouro']) &&
                    isset($ret['complemento']) &&
                    isset($ret['bairro']) &&
                    isset($ret['localidade']) &&
                    isset($ret['uf']) &&
                    isset($ret['ibge']) &&
                    isset($ret['gia'])) &&
                    isset($ret['unidade']);
        }
        return false;
    }
325634
protected function getCampoLivre()
    {
        if ($this->campoLivre) {
            return $this->campoLivre;
        }

        $campoLivre = '2';
        $campoLivre .= '1';
        $campoLivre .= Util::numberFormatGeral($this->getCodigoCliente(), 11); //4 digitos da agencia + 7 primeiros digitos pois os ultimos 2 são digitos verificadores
        $campoLivre .= Util::numberFormatGeral($this->getNumero(), 8);
        $campoLivre .= '40';
        $campoLivre .= CalculoDV::banrisulDuploDigito(Util::onlyNumbers($campoLivre));

        return $this->campoLivre = $campoLivre;
    }
829432
private static function checkType(Meta $m)
    {
        if (in_array($m->getType(), ["tinyint", "smallint", "mediumint", "int", "bigint"])) {
            if (!is_numeric($m->getValue())) {
                if ($m->getDefault() === false)
                    $m->setError("número inválido");
                else
                    $m->setValue("", !1);
            }

        } elseif (in_array($m->getType(), array("double", "real", "float"))) {
            if (!is_numeric($m->getValue())) {
                if ($m->getDefault() === false)
                    $m->setError("valor não é um número");
                else
                    $m->setValue("", !1);
            }

        } elseif (in_array($m->getType(), array("bit", "boolean", "serial"))) {
            if (!is_bool($m->getValue())) {
                if ($m->getDefault() === false)
                    $m->setError("valor boleano inválido. (true ou false)");
                else
                    $m->setValue("", !1);
            }

        } elseif (in_array($m->getType(), array("datetime", "timestamp"))) {
            if (!preg_match('/\d{4}-\d{2}-\d{2}[T\s]+\d{2}:\d{2}/i', $m->getValue())) {
                if ($m->getDefault() === false)
                    $m->setError("formato de data inválido ex válido:(2017-08-23 21:58:00)");
                else
                    $m->setValue("", !1);
            }

        } elseif ($m->getType() === "date") {
            if (!preg_match('/\d{4}-\d{2}-\d{2}/i', $m->getValue())) {
                if ($m->getDefault() === false)
                    $m->setError("formato de data inválido ex válido:(2017-08-23)");
                else
                    $m->setValue("", !1);
            }

        } elseif ($m->getType() === "time") {
            if (!preg_match('/\d{2}:\d{2}/i', $m->getValue())) {
                if ($m->getDefault() === false)
                    $m->setError("formato de tempo inválido ex válido:(21:58)");
                else
                    $m->setValue("", !1);
            }

        } elseif ($m->getType() === "json" && !is_array($m->getValue())) {
            if ($m->getDefault() === false)
                $m->setError("formato json inválido");
            else
                $m->setValue("", !1);
        }
    }
983707
def PBToPy(numpb):
    """"""
    return PhoneNumber(country_code=numpb.country_code if numpb.HasField("country_code") else None,
                       national_number=numpb.national_number if numpb.HasField("national_number") else None,
                       extension=numpb.extension if numpb.HasField("extension") else None,
                       italian_leading_zero=numpb.italian_leading_zero if numpb.HasField("italian_leading_zero") else None,
                       number_of_leading_zeros=numpb.number_of_leading_zeros if numpb.HasField("number_of_leading_zeros") else None,
                       raw_input=numpb.raw_input if numpb.HasField("raw_input") else None,
                       country_code_source=numpb.country_code_source if numpb.HasField("country_code_source") else CountryCodeSource.UNSPECIFIED,
                       preferred_domestic_carrier_code=numpb.preferred_domestic_carrier_code if numpb.HasField("preferred_domestic_carrier_code") else None)
1293374
private boolean checkDeTaxNumber(final String ptaxNumber) {
    final int fa = Integer.parseInt(StringUtils.substring(ptaxNumber, 2, 4));
    final int sb = Integer.parseInt(StringUtils.substring(ptaxNumber, 5, 8));
    final int checkSum = ptaxNumber.charAt(12) - '0';
    if (StringUtils.startsWith(ptaxNumber, "11")) {
      // Berlin
      final int calculatedCheckSum;
      if (fa >= 27 && fa <= 30 //
          || fa < 31 && (sb < 201 || sb > 693) //
          || fa == 19 && (sb < 200 || sb > 639 && sb < 680 || sb > 680 && sb < 684 || sb > 684) //
          || fa == 37) {
        calculatedCheckSum = ((ptaxNumber.charAt(5) - '0') * 7 //
            + (ptaxNumber.charAt(6) - '0') * 6 //
            + (ptaxNumber.charAt(7) - '0') * 5 //
            + (ptaxNumber.charAt(8) - '0') * 8 //
            + (ptaxNumber.charAt(9) - '0') * 4 //
            + (ptaxNumber.charAt(10) - '0') * 3 //
            + (ptaxNumber.charAt(11) - '0') * 2) //
            % MODULO_11;
      } else {
        calculatedCheckSum = ((ptaxNumber.charAt(2) - '0') * 3 //
            + (ptaxNumber.charAt(3) - '0') * 2 //
            + (ptaxNumber.charAt(4) - '0') * 9 //
            + (ptaxNumber.charAt(5) - '0') * 8 //
            + (ptaxNumber.charAt(6) - '0') * 7 //
            + (ptaxNumber.charAt(7) - '0') * 6 //
            + (ptaxNumber.charAt(8) - '0') * 5 //
            + (ptaxNumber.charAt(9) - '0') * 4 //
            + (ptaxNumber.charAt(10) - '0') * 3 //
            + (ptaxNumber.charAt(11) - '0') * 2) //
            % MODULO_11;
      }
      return checkSum == calculatedCheckSum;
    }
    // TODO find checksum calculation routines for the rest
    return true;
  }
125786
public function getRegionCode()
    {
        \preg_match('~^(?<region_digits>[\d]{2}).+$~', $this->getValue(), $matches);

        if (isset($matches['region_digits']) && \is_numeric($region_digits = (string) $matches['region_digits'])) {
            return (int) $region_digits;
        }
    }
423228
private static String getVerifyCode(String idNumber) {
        int sum = 0;
        for (int i = 0; i < 17; i++) {
            sum = sum + Integer.parseInt(String.valueOf(idNumber.charAt(i))) * Integer.parseInt(Wi[i]);
        }
        return ValCodeArr[sum % 11];
    }
794339
def _number_type_helper(national_number, metadata):
    """"""
    if not _is_number_matching_desc(national_number, metadata.general_desc):
        return PhoneNumberType.UNKNOWN
    if _is_number_matching_desc(national_number, metadata.premium_rate):
        return PhoneNumberType.PREMIUM_RATE
    if _is_number_matching_desc(national_number, metadata.toll_free):
        return PhoneNumberType.TOLL_FREE
    if _is_number_matching_desc(national_number, metadata.shared_cost):
        return PhoneNumberType.SHARED_COST
    if _is_number_matching_desc(national_number, metadata.voip):
        return PhoneNumberType.VOIP
    if _is_number_matching_desc(national_number, metadata.personal_number):
        return PhoneNumberType.PERSONAL_NUMBER
    if _is_number_matching_desc(national_number, metadata.pager):
        return PhoneNumberType.PAGER
    if _is_number_matching_desc(national_number, metadata.uan):
        return PhoneNumberType.UAN
    if _is_number_matching_desc(national_number, metadata.voicemail):
        return PhoneNumberType.VOICEMAIL

    if _is_number_matching_desc(national_number, metadata.fixed_line):
        if metadata.same_mobile_and_fixed_line_pattern:
            return PhoneNumberType.FIXED_LINE_OR_MOBILE
        elif _is_number_matching_desc(national_number, metadata.mobile):
            return PhoneNumberType.FIXED_LINE_OR_MOBILE
        return PhoneNumberType.FIXED_LINE

    # Otherwise, test to see if the number is mobile. Only do this if certain
    # that the patterns for mobile and fixed line aren't the same.
    if (not metadata.same_mobile_and_fixed_line_pattern and
        _is_number_matching_desc(national_number, metadata.mobile)):
        return PhoneNumberType.MOBILE
    return PhoneNumberType.UNKNOWN