Console failure (Can not set property 'value' of null)

0

I get errors in the console with the following explanation: Uncaught TypeError: Can not set property 'value' of null

Matches the line of this JavaScript code

if(!re.exec(document.getElementById("tel").value="")){

this would be the complete code

function validar() {
  //Validación de teléfono
  re=/^(6|7|8|9) [0-9] {8}$/;

  if(!re.exec(document.getElementById("tel").value="")){
    alert('El teléfono no es válido');
  }else {
    valor = document.getElementById("tel").value;
    if( !(/^\d{9}$/.test(valor))){
      alert('El teléfono debe tener 9 cifas');
    } else if(isNaN(rel)){
      alert("El telefono no es un número");
    }
  }
}

the html:

<div id="datos_left">
<input type="tel" id="tel" maxlength="9" placeholder="Teléfono fijo o móvil" 
required> </p><input type="button" value="Enviar formulario" id="enviar" 
onsubmit="validar();"/>
</form>
</div>
    
asked by Marta 19.06.2017 в 12:50
source

0 answers