Validation of Data Length (Sample Northwind - Products)
     

Rule 1: Whenever you have a data entry page you should always use the MaxLength property to the same as the length of the field in the table(except for numbers).

       State: (maxlength="3")

Rule 2: Whenever you have a situation where you are using:

  • the HTML TEXTAREA (does not have the maxlength property), or
  • have a SQL Server table exceeding the limit of 8060 bytes. (Developers sometimes define the table with char/varchar sizes that exceed this, in order to give the user flexibility in which fields they want to store the data).

eg.

Then you need to:

  •  add the javascript function eg. ValidateLength(control)
  •  add 2 properties to every data control  eg. dataType="char" onkeyup="validateLength(this)"

More information:

The below form demonstrates the client side validation that is required on a HTML page. The javascript function calculates the bytes (based on the data type and field size).

Once 8060 bytes are used the user is given a visual indications about the remain size left.
 

Product ID: int
Product Name: char
Quantity per unit: varchar
Units in stock:    datetime
Category: varchar
Units on order: smallint
Unit Price: money
Discontinued: 1 2 3 4 5 6 7 8 9 10 11 12 13 bit
Note 1 nvarchar
Note 2 nvarchar
Note :Once you type more than 8060 bytes then you won't be able to submit the page.
Row size  of characters you typed:
0
Row size  of characters left:
8060