Hi,
I have an input textbox that runs a js function on the keyup event to match for a valid string (domain name pattern match, the regex was found on here).
I wrote the if statements to test whether the input is a valid pattern first and then more than 3 characters long.
Apparently, my ifs don't work like I wanted them to. When the input has 3 or more characters, it is fine.
But if the input is less than 3 characters, it fails the pattern regex.
Example: if the input box has "dd" (no quotes), the function will alert that I have an incorrect pattern when it SHOULD alert that the input is less than 3 characters long.
From the alert statement included, there is no extra spaces or characters in the input value.
<input id="quick" type="text" size="20" onKeyUp="test()"></input>
the function test is
function test(){
   var liveword = document.getElementById("quick").value;
   var valid = /^[a-zA-Z0-9][a-zA-Z0-9\-\_]+[a-zA-Z0-9]$/;
  alert("xxx"+liveword+"xxx");
    if (liveword.match(valid))
   {
        if (liveword.length < 3)
        {
        alert ('word less than 3');
        }
        else {
    alert ('word more than 3');
            }
     }//outside if
     else {
         alert('enter correct pattern');
     }  
} //close
TIA for your help.