Verify the length of jQuerytextarea _ jquery

Source: Internet
Author: User
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:
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.