The Textarea control cannot use formvalidate. js to determine the attributes of. Extended textarea. Combined with jquery. validate. js, it also verifies the length of textarea when submitting a form.
1. jQuery plugin for verifying the length of textarea
The Code is as follows:
// Verify the textarea Length
JQuery. fn. checkLength = function (parameters ){
Defaults = {
Min: 0
, Max: 5
}
JQuery. extend (defaults, parameters );
// Current textarea Value
Var taValue = $ (this). val ();
Var len = taValue. length;
If (len> = defaults. max ){
$ (This). parent (). append (showLengthError ("max"). show ();
Window. setTimeout (function (){
$ (". LenError"). hide ();
},5000 );
Return false;
} Else if (len <= defaults. min ){
$ (This). parent (). append (showLengthError ("min "));
Window. setTimeout (function (){
$ (". LenError"). hide ();
},5000 );
Return false;
} Else {
Return true;
}
// Todo: When the keyboard input is in the correct range, eliminate the prompt.
}
Note:
1) parameter transfer:
Defaults = {
Min: 0
, Max: 5
}
It is used to receive the shortest and maximum length of textarea respectively.
2) Return Value
True: The verification length passes
False: verification length failed
2. Instructions for use:
Add js reference on the page: