javascript|字符串
<script language="javascript">
<!--
function textCounter(field,maxlimit)
{
var str="";
str=field.value;
str=str.replace(/[^\x00-\xff]/g,"**");
if (str.length > maxlimit)
{
// field.value = field.value.substring(0, maxlimit);
field.value=getByteOfNum(field.value,maxlimit);
}
}
function getByteOfNum(val, num)
{
var ch,bytenum=0;
var rs = "";
var pt = /[^\x00-\xff]/;
for (var i=0; i < num; i++)
{
ch = val.substr(i, 1);
if (ch.match(pt))
{
bytenum += 2;
if (bytenum > num)
{
return rs;
}
}else
{
bytenum += 1;
}
rs += ch;
if (bytenum == num)
{
return rs;
}
}
return rs;
}
//-->
aspx中调用的代码:
<asp:textbox id="txtAttendOuter" runat="server"
onkeyup="textCounter(this.form.txtAttendOuter,100);" Width="145px"></asp:textbox>