0
Good, I have a class "Entity", where I have the property "Phone", for the phone, I have a function the part that validates the phone number "isvalidTelephone", I also have a function that prints all properties... My doubt is of beginner.. How do I do instead of it simply echo the phone number, print the phone number by going through the validation of "isvalid"?
Here is my code:
GETTER AND SETTER:
public function getTelefone() {
return $this->telefone;
}
/**
* @param mixed $telefone
*/
public function setTelefone($telefone) {
if ($telefone === $this->isvalidTelefone($telefone)) {
echo "este numero esta errado";
} else {
echo "este numero esta certo";
}
}
VALIDATION FUNCTION:
public function isvalidTelefone($telefone) {
if ((strlen($telefone) < 9) || (strlen($telefone) > 9)) {
return FALSE;
} else {
return TRUE;
}
}
FUNCTION THAT PRINTS PROPERTIES:
public function printEntidade() {
return $this->nome . '<br>' .
$this->email . '<br>' .
$this->nif . '<br>' .
$this->codpostal . '<br>' .
$this->localidade . '<br>' .
$this->morada . '<br>' .
$this->pais . '<br>' .
$this->telefone . '<br>' .
$this->saldo;
}
Thank you!
Opa Nelson, you want to print the phone number only if it is valid?
– André Lins
Hello Andre, yes that’s it, I want you to print if the number is valid, IE, I want the setTelefone has the validation function.
– Nelson Pacheco