以下JavaScript校验日文环境下的用户输入
直接调用fvallenchk函数即可,obj为要校验的对象,max_len为最大长度,该函数返回0表示长度超出,反之则通过.
function fgetdata(Obj){
wkValue = "";
wkType = Obj.type;
if (wkType == "text") {
wkValue = Obj.value;
} else if (wkType == "hidden") {
wkValue = Obj.value;
} else if (wkType == "select-one") {
SelIx = Obj.selectedIndex;
wkValue = Obj.options[SelIx].value;
} else if (wkType == "textarea") {
wkValue = Obj.value;
} else if (wkType == "password") {
wkValue = Obj.value;
}
return wkValue;
}
function fvallenchk(obj,max_len){
var chkstr,i,cnt = 0;
chkstr = "????????`??????????????????????????????????????????????????";
strValue = fgetdata(obj);
for(i=0; i<strValue.length; i++){
if(escape(strValue.charAt(i)).length >= 4 ){
if ( chkstr.indexOf(strValue.charAt(i))== -1){
cnt+=2;
}else{
cnt++;
}
}else{
cnt++;
}
};
if (cnt > max_len) {
return "0";
} else {
return "1";
}
}
本文地址:http://com.8s8s.com/it/it15259.htm