Skip to content

Instantly share code, notes, and snippets.

@leonardop21
Created June 16, 2021 17:35
Show Gist options
  • Select an option

  • Save leonardop21/0a04edd643fb5a9160a7203791fa82b7 to your computer and use it in GitHub Desktop.

Select an option

Save leonardop21/0a04edd643fb5a9160a7203791fa82b7 to your computer and use it in GitHub Desktop.
validação cep range 2
<?php
Class Cep {
private $cep;
private $intervalosCep;
public function __construct($cep){
$this->intervalosCep = [['09000001', '09399999'], ['09600001', '09899999'], ['09500001', '09599999']];
$this->cep = $this->validate($cep);
}
public function getCep(){
return $this->cep;
}
public function getIntervalosCep(){
return $this->intervalosCep;
}
public function validate($cep){
$valorCep = preg_replace("/\D/", "", $cep);
foreach($this->intervalosCep as $cep){
list($min, $max) = $cep;
if($valorCep >= $min && $valorCep < $max) {
return $this->cep = true;
}else {
return $this->cep = false;
}
}
}
}
$teste = new Cep('09003211');
echo $teste->getCep();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment