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!");
}