Hi,I am trying to verify form input for length(before that I would like to trim it)
How can I do that for user
Thanks

function verify(){
var user=document.getElementById("user");
var pass=document.getElementById("pass");
var msg= "";
document.write("Length "+user.length);
if(user.value == ""){
  msg+= "Please enter a username!\n";
  user.className = "inpBoxError";
  }
if(pass.value == ""){
  msg+= "Please enter a password!\n";
  pass.className = "inpBoxError";
  }
  if(msg == ""){
  return true;
  }
  else
  {
  alert(msg);
  return false;
  }
 }
</script>
<table border="0">
<form action="index.htm" method="post" onSubmit="return verify();">
<tr colspan="2" allign="center"><td> Form Name</td></tr>
<tr><td>User</td>
<td><input type="text" name="user" id="user" class="inpBox"></td></tr>
<tr><td>Pass</td>
<td><input type="password" name="pass" id="pass" class="inpBox"></td></tr>
<tr><td colspan="2"  align="center">
<input type="submit" value="Enter" name="submit"></td></tr>
</form>
</table>

line 5: user.value.length
will give you the length of the string in the text box, though you've probably figured this out by now

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.