Field Length Validation

I would Like to write a function that validates the lenght of a field (Textbox).
<input type="TextBox" name="Field1" value="" onblur="ValidateLength(10);" > 
ValidateLength function should return a false if the value of field has more than 10 chars.  
Who is Participating?
sybeConnect With a Mentor Commented:
function ValidateLength(field, nr) {
  if (field.value.length > nr) {
    alert('don't enter more then ' + nr + ' characters');


<input type="TextBox" name="Field1" value="" onblur="ValidateLength(this,10);" > 
<input type="TextBox" name="Field1" value="" OnKeyPress="AllowNumbersOnly();" > 

function AllowNumbersOnly(){
   if ((event.keyCode < 48) || (event.keyCode > 57))event.returnValue = false;

This only works in IE 3 and Above
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.