Asp.Net gives invariably a cool and very good built properties in
controls like MaxLength property for a TextBox which doesn’t allows a
user to enter more than the specified length. But this property do not
work well with a MultiLine TextBox (TextMode= MultiLine).
To resolve this problem one can either use a JavaScript function to check the number of characters entered in the MultiLine TextBox and then return false in case the value exceeds the developers expected length.
The other and a much simpler way to do this is to use a RegularExpressionValidator Control.
This can be done in following steps:-
1. Drag and drop a RegularExpressionValidator and set its ControlToValidate property to the multiline TextBox.
2. In the ExpressionValidation write the expression :
^[\s\S]{“Your Minimum Length,”Your Maximum Length”}$
Example:- ^[\s\S]{3,10}$
where ^ denotes start of string, \s\S denotes spacial and non-spacial characters and {3,10} denotes minimum of three and a maximum of 10 characters can be entered. $ represents the end of string
To resolve this problem one can either use a JavaScript function to check the number of characters entered in the MultiLine TextBox and then return false in case the value exceeds the developers expected length.
The other and a much simpler way to do this is to use a RegularExpressionValidator Control.
This can be done in following steps:-
1. Drag and drop a RegularExpressionValidator and set its ControlToValidate property to the multiline TextBox.
2. In the ExpressionValidation write the expression :
^[\s\S]{“Your Minimum Length,”Your Maximum Length”}$
Example:- ^[\s\S]{3,10}$
where ^ denotes start of string, \s\S denotes spacial and non-spacial characters and {3,10} denotes minimum of three and a maximum of 10 characters can be entered. $ represents the end of string