validation - Javascript checking telephone number - IF Statement -


my if statement isn't working 100%; want checking length , if digits, if left blank green text , style errtelno1 - can me understand why? i'm new @ this...its 11 digit number

if (document.getelementbyid("telno").value.length != 11 ) {     document.getelementbyid("errtelno").style.display = "inline";     document.getelementbyid("errtelno").style.visibility = "visible";     document.getelementbyid("telno").style.border ='4px solid red';     document.getelementbyid("errtelno").style.color = "green";     document.getelementbyid("errtelno").style.fontweight = "light";     document.getelementbyid("errtelno").style.fontsize = "12px";     isvalid = false; }   else {       document.getelementbyid("telno").style.border ='2px solid green';         document.getelementbyid("errtelno").style.color = "green";  }  if (document.getelementbyid("telno").value != /^\d+$/ ) {     document.getelementbyid("errtelno1").style.display = "inline";     document.getelementbyid("errtelno1").style.visibility = "visible";      document.getelementbyid("telno").style.border ='4px solid red';      isvalid = false; }   else {       document.getelementbyid("telno").style.border ='2px solid green'; } return isvalid;  } 

a little sample shorten problem. sample...

var telno = document.getelementbyid("telno"); var errtelno = document.getelementbyid("errtelno"); var expr = /^\d+$/; var isvalid = (telno.value.length == 11 && expr.test(telno.value));  if(!isvalid) {   errtelno.style.display = "inline";   errtelno.style.visibility = "visible";   telno.style.border ='4px solid red';   errtelno.style.color = "green";   errtelno.style.fontweight = "light";   errtelno.style.fontsize = "12px"; } else {   telno.style.border ='2px solid green';   errtelno.style.color = "green"; } return isvalid; 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -