Validate the length of an input with Javascript [closed]

0

How about?
I would not be validating that the phone has less than 8 characters I tried to do it with onblur but it bugea when I put email I also tried with onsubmit (which would be ideal directly) but still doing nothing Any suggestions are welcome

<!DOCTYPE html>
<HTML LANG="es">
<HEAD><meta charset="utf-8"/>
<link rel="stylesheet" type="text/css" href="estilo.css">
<title>Contacto</title>
<script>
function ValidarEmail(mail)
{
if(mail.value.indexOf("@")==-1)
{
alert ("Mail invalido")
mail.focus()
mail.select()
}
}
function ValidarTelefono(fono)
   {
if(fono.value.lenght < 8)
{
alert ("Escriba su número completo")
fono.focus()
fono.select()
}
}     

</script>
</head>
<body background="imagenes/fondo4.jpg">
<font color= black size=4>
Contacto 
<hr>
<form name="Contacto" action="mailto:[email protected]" method=post onsubmit="submit()">
Nombre: <input type=text name=nombre style="width: 12.3em"> <br><br>
E-mail: <input type=email name=email style="width:13.05em " onchange="return ValidarEmail(this)"> <br><br>
Teléfono: <input type=number name=tel style="width: 11.95em" onchange="return ValidarTelefono(this)"> <br><br>
Asunto: <input type=text name=asunto style="width: 12.85em"> <br> <br>
¿Desea recibir informaciòn en su correo? <input type= radio name=info checked value=cy> Sí <input type=radio name= info value=ño> No <br> <br>
Escriba su consulta:<br> <textarea rows=10 cols=80 name=consulta noresize> </textarea>
<br><br>
Ingrese su código de socio (en caso de que haya comprado anteriormente): <input type=password maxlength=4 size=6 name=cod> <br> <br>
<input type=reset value="Borrar todo">
<input type=submit value="Enviar">	
</form></font>
    
asked by Facundo Bernkastel Oviedo 13.01.2018 в 04:39
source

1 answer

0
  

Hello how are you? , the problem is that you are misplacing the property of the input object.

     

You put lenght instead of length

function ValidarEmail(mail) {
  if (mail.value.indexOf("@") == -1) {
    alert("Mail invalido");
    mail.focus();
    mail.select();
  }
}

function ValidarTelefono(fono) {
  //if (fono.value.lenght < 8) {
  if (fono.value.length < 8) {
    alert("Escriba su número completo");
    fono.focus();
    fono.select();
  }
}
<font color=b lack size=4>
  Contacto
  <hr>
  <form name="Contacto" action="mailto:[email protected]" method=post onsubmit="submit()">
    Nombre: <input type=text name=nombre style="width: 12.3em"> <br><br> E-mail: <input type=email name=email style="width:13.05em " onchange="return ValidarEmail(this)"> <br><br> Teléfono: <input type=number name=tel style="width: 11.95em" onchange="return ValidarTelefono(this)">    <br><br> Asunto: <input type=text name=asunto style="width: 12.85em"> <br> <br> ¿Desea recibir informaciòn en su correo? <input type=r adio name=info checked value=cy> Sí <input type=radio name=i nfo value=ño> No <br> <br> Escriba su consulta:<br>    <textarea rows=10 cols=80 name=consulta noresize> </textarea>
    <br><br> Ingrese su código de socio (en caso de que haya comprado anteriormente): <input type=password maxlength=4 size=6 name=cod> <br> <br>
    <input type=reset value="Borrar todo">
    <input type=submit value="Enviar">
  </form>
</font>
EjecutarCopiar a respuestaEsconder resultados
    
answered by 13.01.2018 / 05:10
source