JS 方法:
function fucCheckLength(strTemp)
{
var i,sum;
sum=0;
for(i=0;i<strTemp.length;i++)
{
if ((strTemp.charCodeAt(i)>=0) && (strTemp.charCodeAt(i)<=255))
sum=sum+1;
else
sum=sum+2;
}
return sum;
}
.Net 服务端
public bool CheckLen(string str, int intlen)
{
bool blnResult = false;
int n = 0;
int intLenAct = 0;
for (n = 1; n <= Strings.Len(str); n++) {
if (Strings.AscW(Strings.Mid(str, n, 1)) > 256) {
intLenAct = intlen + 2;
} else {
intLenAct = intlen + 1;
}
}
if (intLenAct <= intlen) {
blnResult = true;
}
return blnResult;
}