Check whether the form meets the specified length. The maximum allowed is n characters (Chinese is counted as 2 characters)!
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:
m= fucCheckLength(strTemp);
if(m>10){
alert("Length is greater than 10 characters!");
}
Statement: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