Home > Web Front-end > JS Tutorial > Specific examples of JS verification control input Chinese and English byte length (input, textarea, etc.)_javascript skills

Specific examples of JS verification control input Chinese and English byte length (input, textarea, etc.)_javascript skills

WBOY
Release: 2016-05-16 17:32:01
Original
1075 people have browsed it

Check whether the form meets the specified length. The maximum allowed is n characters (Chinese is counted as 2 characters)!

Copy code The code is as follows:

function fucCheckLength(strTemp) {
var i, sum;
sum=0;
for(i=0;i if ((strTemp.charCodeAt(i)>=0) && (strTemp.charCodeAt( i)<=255)) {
sum=sum 1;
}else {
sum=sum 2;
}
}
return sum;
}

Use:
Copy code The code is as follows:

m= fucCheckLength(strTemp);
if(m>10){
alert("Length is greater than 10 characters!");
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template