Last active
June 16, 2021 17:51
-
-
Save leonardop21/3e7e4a5cd56a62b68c1630e95eea91d7 to your computer and use it in GitHub Desktop.
Validação de range de cep
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| Class Cep { | |
| private $cep; | |
| public function setCep($cep){ | |
| $this->cep = $this->validate($cep); | |
| } | |
| public function getCep(){ | |
| return $this->cep; | |
| } | |
| public function validate($cep){ | |
| $valorCep = preg_replace("/\D/", "", $cep); | |
| $intervalosCep = [['09000001', '09399999'], ['09600001', '09899999'], ['09500001', '09599999']]; | |
| foreach($intervalosCep as $cep){ | |
| list($min, $max) = $cep; | |
| if($valorCep >= $min && $valorCep < $max) { | |
| return $this->cep = true; | |
| }else { | |
| return $this->cep = false; | |
| } | |
| } | |
| } | |
| } | |
| $teste = new Cep(); | |
| $teste->setCep('091111121'); | |
| echo $teste->getCep(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment