|
|
|
|
|
用JavaScript判断字符串长度http://www.xishui.net 2008年07月12日16:13 浠水网
《SCRIPT LANGUAGE="JavaScript"》
《!-- function a() { var totallength=0; for (var i=0;i《document.forma.sUserName.value.length;i++) { var str=document.forma.sUserName.value; var intCode=str.charCodeAt(i); if (intCode》=0 && intCode《=128) {//continue; totallength=totallength+1; } else { totallength=totallength+2; } } //end for alert(totallength); if (totallength《3 || totallength》20) { document.forma.sUserName.select(); alert("用户名必须是3-20个字符!请重新输入。"); return false; } return true; } //--》 《/SCRIPT》
【发表评论】
|
|||||||||||