Skip to content

Instantly share code, notes, and snippets.

@leonardop21
Last active June 16, 2021 17:51
Show Gist options
  • Save leonardop21/3e7e4a5cd56a62b68c1630e95eea91d7 to your computer and use it in GitHub Desktop.
Save leonardop21/3e7e4a5cd56a62b68c1630e95eea91d7 to your computer and use it in GitHub Desktop.

Revisions

  1. leonardop21 revised this gist Jun 16, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion validate-range-cep.php
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    Class Cep {
    private $cep;
    private $intervalosCep;


    public function setCep($cep){
    $this->cep = $this->validate($cep);
  2. leonardop21 revised this gist Jun 16, 2021. 1 changed file with 0 additions and 5 deletions.
    5 changes: 0 additions & 5 deletions validate-range-cep.php
    Original file line number Diff line number Diff line change
    @@ -12,11 +12,6 @@ public function getCep(){
    return $this->cep;
    }


    public function getIntervalosCep(){
    return $this->intervalosCep;
    }

    public function validate($cep){
    $valorCep = preg_replace("/\D/", "", $cep);

  3. leonardop21 created this gist Jun 16, 2021.
    41 changes: 41 additions & 0 deletions validate-range-cep.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    <?php

    Class Cep {
    private $cep;
    private $intervalosCep;

    public function setCep($cep){
    $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);

    $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();