I have this code:
switch (cpf) {
case this.aluno.cpf.length == 0:
this.cpfVazio = true;
break;
case this.aluno.cpf.length != 14:
this.cpfVazio = true;
break;
default:
this.cpfVazio = false;
break;
}
this.aluno.cpf is a string. And it is not comparing always going to default. Does anyone know what is wrong?
Here is the HTML code and the class Aluno:
<ion-item>
<ion-label position="floating">CPF*</ion-label>
<ion-input type="text" [(ngModel)]="aluno.cpf" [brmasker]="{mask: '000.000.000-00', len:14, type:'num'}" (ionBlur)="validaCpf(aluno.cpf)" (ionChange)="validaCpf(aluno.cpf)" name="cpf" required></ion-input>
</ion-item>
<small class="mensagem-erro" *ngIf="cpfVazio" name="cpf">Este campo é obrigatório!</small><br>
export class Aluno {
inscricao = "";
dataInscricao = "";
nome = "";
dataNascimento = "";
cpf = "";
endereco = "";
cidade = "";
bairro = "";
cep = "";
contatos = "";
email = "";
facebook = "";
igreja = "";
soube = "";
proposito = "";
historico = "";
}
switchbut severalif.minLengthandmaxLengthof 14 would be easier?