Form length Validated with User Input

[Total: 0    Average: 0/5]

This will determine if the string input in the textbox is the correct length.

Head Code:

<script type="text/javascript">
function checkLength(_str,_len)
{
  var _slen=_str.toString().length;
  if(!_slen || _len=="")
    return false;
  else if(_len<_slen)
    alert( "{ipb.lang['l_over']}" + _len + " {ipb.lang['l_characters']}." );
  else if(_len==_slen)
    alert( "{ipb.lang['l_equal']}" + _len + " {ipb.lang['l_characters']}." );
  else
    alert( "{ipb.lang['max_is']}" + _len + " {ipb.lang['l_characters']}. {ipb.lang['youve_used']}" + _slen + " {ipb.lang['l_characters']}." );
}
</script>

Body Code:

This checks the length of the string for equal, under or over the length.
<form name=f1>
String:<input type=text name=t1 value="abcdefghi"><BR>
Length:<input type=text name=t2 value="3"><BR>
<input type=button onclick="checkLength(this.form.t1.value,this.form.t2.value)" value="Check length">
</form>

Times Viewed: 8

Leave a Reply

Your email address will not be published. Required fields are marked *