Validates a telephone/cell phone number

@param string $tel Maximum format '+00 (000) 90000-0000'

@return string validated or false on failure
488835
public static function tel($tel)
    {
        if (preg_match("/^(\+\d{2}|)\s?(\(?0?\d{2}\)?|)\s?(9?)\s?(\d{4})[\s\-]?(\d{4})$/", $tel, $matches)) {
            return ($matches[1] !== '' ? $matches[1] . ' ' : '')
                 . ($matches[2] !== '' ? implode('', array_diff(str_split($matches[2]), ['(',')'])) . ' ' : '')
                 . $matches[3]. $matches[4] . '-' . $matches[5];
        }
        return false;
    }
599295
public static function validate($hetu)
    {
        if (!is_string($hetu) || strlen($hetu) != 11) {
            return false;
        }

        $dd = substr($hetu, 0, 2);
        $mm = substr($hetu, 2, 2);
        $yy = substr($hetu, 4, 2);
        $centuryCode = strtoupper($hetu{6});
        $id = (int) ($dd.$mm.$yy.substr($hetu, 7, 3));
        $checksum = strtoupper($hetu{10});

        if ($dd < 1 || $dd > 31) {
            return false;
        }

        if ($mm < 1 || $mm > 12) {
            return false;
        }

        if (!is_numeric($yy)) {
            return false;
        }

        if (!array_key_exists($centuryCode, static::$centuryCodes)) {
            return false;
        }

        $hetuChecksumKey = $id % strlen(static::$validationKeys);
        if (!isset(static::$validationKeys{$hetuChecksumKey})
            || static::$validationKeys{$hetuChecksumKey} !== $checksum
        ) {
            return false;
        }

        return true;
    }
734614
public function validate($input)
    {
        /**
         * Validation criteria:
         * - 8 or 9 digits (only numbers!)
         * - Be able to pass the '11 test'
         * - Musn't contain any information.
         *   Cannot implement at this stage, not clear enough defined! Is 1337 information?
         * - Can not be sequential (nummeric)
         * - Is not 900000000 through 999999999 (test numbers)
         *
         * Based on public information: http://nl.wikipedia.org/wiki/Burgerservicenummer
         */

        // Validate: 8 or 9 digits (only numbers!)
        if (strlen($input) < 8 || strlen($input) > 9) {
            return false;
        }

        // Check if they are actually numbers
        // Alternatively, use ctype_digit($input) !
        if (preg_match('/[^0-9]/', $input)) {
            return false;
        }

        // See if the number passes the Eleventest (http://nl.wikipedia.org/wiki/Elfproef)
        if ($this->elevenTest($input)) {
            return false;
        }

        // Check if the numbers are sequential
        // Will not match when sequential numbers are used
        if (preg_match('/\d{5}/u', $input)) {
            return false;
        }

        // Validate if the number is not in the test range!
        return filter_var(
            $input,
            FILTER_VALIDATE_INT,
            array('options' => array('min_range' => '900000000', 'max_range' => '999999999'))
        );
    }
434551
public static function isValidPhoneNumber($phoneNumber)
    {
        /*
         * Not a string?
         * Nothing to do
         */
        if (!is_string($phoneNumber)) {
            return false;
        }

        $pattern = self::getPhoneNumberPattern();

        return (bool)preg_match($pattern, trim($phoneNumber));
    }
156544
public function validateVatNumber(string $vatNumber) : bool
    {
       return $this->validateVatNumberFormat($vatNumber) && $this->validateVatNumberExistence($vatNumber);
    }
1023532
public function validate(string $string)
	{
		$validated = mb_substr($string, static::MAC_LENGTH, null, '8bit');

		if(hash_equals($this->getSignature($validated), mb_substr($string, 0, static::MAC_LENGTH, '8bit')))
		{
			return $validated;
		}

		return false;
	}
1310716
public function sendVerifyCode($phone){
		$code = $this->verifyCode(6);
		$vct = config('dysms.Verify_Code_Template');
		$resp = $this->sendSms($vct, $phone, ['code'=> $code], null);
		$cacheKey = static::CACHE_PREFIX . $phone;
		$expiresAt = Carbon::now()->addMinutes(15);
		Cache::put($cacheKey, $code, $expiresAt);
		return $resp;
	}
711071
public function validate($value)
    {
        if (!is_numeric($value)) {
            return false;
        }

        return $value / $this->number == round($value / $this->number);
    }
813189
public static function sanitize_phone(&$phone = '') {
		r_cast::string($phone, true);

		// Replace number chars.
		$from = \array_keys(constants::NUMBER_CHARS);
		$to = \array_values(constants::NUMBER_CHARS);
		$phone = \str_replace($from, $to, $phone);

		$phone = \preg_replace('/[^\d]/', '', $phone);

		if (! c_data::length_in_range($phone, static::MIN_LENGTH, static::MAX_LENGTH)) {
			$phone = false;
		}

		return true;
	}
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;
    }
1301595
private function validateOld(string $vatNumber): string
    {
        $checkval = substr($vatNumber, 2);
        $checkval .= "12";
        $checkval = intval($checkval) % 97;

        return $checkval == 0 ? "00" : (string) $checkval;
    }
1260697
public static function isValid(string $number) : bool
    {
        if (ctype_digit($number)) {
            return self::checksum($number) === 0;
        }

        return false;
    }
902618
private function validatePhysical(string $vatNumber): string
    {
        $vatNumber[0] = str_replace(['Y', 'Z'], [1, 2], $vatNumber[0]);

        if (ctype_digit($vatNumber[0])) {
            $checkval = ((int)substr($vatNumber, 0, 8) % 23) + 1;
        } else {
            $checkval = ((int)substr($vatNumber, 1, 7) % 23) + 1;
        }

        return $this->checkCharacterPhysical[$checkval];
    }
1184839
public static function formatPhone($phone)
    {
        $ddd = '';
        $phone = self::keepOnlyNumbers($phone);

        // removes leading zero
        if (substr($phone, 0, 1) == 0) {
            $phone = substr($phone, 1);
        }

        // verifies if have ddd
        if (strlen($phone) > 9) {    
            //removes country identifier
            if (strlen($phone) > 11) {
                $phone = substr($phone, 2);
            }
            $ddd = substr($phone, 0, 2);
            $phone = substr($phone, 2);
        }

        return ['areaCode' => $ddd, 'number' => $phone];
    }
710105
def validate_phone(attribute, **options)
      options.reverse_merge!(phone_format: :india)
      if options[:phone_format] == :us
        reg_exp = /\A[0-9]{3}[-][0-9]{3}[-][0-9]{4}\z/
        length = 12
      else
        reg_exp = /\A[0-9]{10}\z/
        length = 10
      end
      options.merge!(format: reg_exp, min_length: length, max_length: length)
      options.reverse_merge!(numericality: true, mandatory: true, uniqueness: true)
      voptions = generate_validation_options(attribute, options)
      validates attribute, **voptions
    end
1060160
function validateNum() {
        var pass = true,
        num = '';

        ['#areacode', '#phnum1', '#phnum2'].forEach(function(id) {
            var $e = $(id),
            val = $e.val();

            if(!val || val.length !== parseInt($e.attr('maxlength'), 10)) {
                pass = false;
                $e.addClass('error');
            }
            else
                num += val;
        });

        if(!pass) return false;

        return num;
    }
992987
public function validate($validator)
    {
        // First check if value is numeric
        if ($this->value && $this->isNumeric()) {
            // Convert to a number to check
            $value = $this->value + 0;
            
            if(is_int($value)) {
                return true;
            }
        }
        
        $validator->validationError(
            $this->name,
            _t(
                'Checkout.VALIDATION', '{value} is not a valid number, only whole numbers can be accepted for this field',
                array('value' => $this->value)
            ),
            "validation"
        );
        return false;
    }