Contents Home Page Previous Page Next Page

Form Input Length

Sometimes your forms may require entries to fit certain length requirements. This script will check for maximum and minimum lengths and ask the user to try again if the requirements are not met.

If you only need to check for maximum length, leave out the lines:

if (form.test.value.length < min) {
alert("Please do not enter less than 4 characters. Please change your entry and submit again.");
return false;
   }
Similarly, for a minimum length only, leave out:
if (form.test.value.length > max) {
alert("Please do not enter more than 12 characters. Please change your entry and submit again.");
return false;
   }


Please type 4 characters or more but no more than 12.