2
I have a form and I need this field
<label class="labVal210Esq">Telefone:
<input type="text" class="val120Dir"
name="TxtTelefone" /> </label>
In case it is the phone, it displays the following error messages:
If the user enters less than 8 digits that an error message appears, a alert("Telefone tem de ter 8 dígitos!")
.
If the user type "-" which is an invalid character, an Alert with = alert("Carácter inválido, somente dígitos).
And if the number is valid (8 digits) nothing appears.
My code:
function VerificaTelef (ident, campo) {
var i, c;
var strTel = campo.value;
if ( strTel.length !=8 ){
alert ("Telfone tem de ter 8 dígitos!");
return false;
}
for (i = 0; i < 8; i++ ){
c = strTel.charAt (i);}
if ( (c < '0') || (c > '9')){
alert("Telefone só pode ter 8 dígitos");
return false;
}}
return true;
}
It’s not working out.
The reference in HTML for javascript has to be by onKeyup if possible, because javascript has to check after the user type.
Sincerely yours,
Gabriel
What is the ident variable?
– Sergio