Maybe there are a lot of similar articles on the Internet, but here you should know, JS inside, Chinese and letter length is 1, but the database does not know Ah, a lot of database are in accordance with the byte, so, control the number of bytes in the input box seems to be more important than the length limit.
Ask a question:
1, the Limit text box is 16 bytes, only input Chinese and letters
Solution Idea:
1, the judgment can only be Chinese and English
2, the judge length can only be 16
3, there is a non conformance, will enter the loop:
The first step: Replace all the #, because I want to use this special character later
Step two: Replace all Chinese with: @@
Step three: Intercept the 0-20 byte length, where the Chinese has been turned into two lengths
Step Fourth: Convert all @@ 转换 #
Fifth step: Replace the last possible Chinese half byte, a @
Step sixth: Get the last remaining character length, which is the length of the string to intercept
<!
DOCTYPE html>