The length of string input in the JS verification text box. Chinese characters are supported.

Source: Internet
Author: User

 

JS Code

Function checklen (OBJ, Len ){
If (obj. value. Replace (/[^/x00-/xFF]/g, '**'). length> = Len ){
OBJ. value = leftutfstring (obj. Value, Len );
}
}
 
Function getstringutflength (STR ){
VaR value = Str. Replace (/[^/x00-/xFF]/g ,"");
Return Value. length;
}

 

Function leftutfstring (STR, Len ){
If (getstringutflength (STR) <= Len)
Return STR;
VaR value = Str. substring (0, Len );
 
While (getstringutflength (value)> Len ){
Value = value. substring (0, value. Length-1 );
}
Return value;
}

 

 

Call method: (onkeyup (this, character length) is as follows: if the number of characters exceeds 1000 (or 500 Chinese characters, the text box cannot be entered, copy and paste the content after 1000 characters)

<Textarea Cols = "65" rows = "4" name = "txtremarkitem" id = "txtremarkitem" onkeyup = "checklen (this, 1000)"> </textarea>

 

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.