实现函数代码如下:
function isCharsInBag (s, bag)
{
var i,c;
for (i = 0; i < s.length; i++)
{
c = s.charAt(i);//字符串s中的字符
if (bag.indexOf(c) > -1)
return c;
}
return \"\";
}
检查函数:
function ischinese(s)
{
var errorChar;
var badChar = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789><,[]{}?/+=\\\\\''\\\":;~!#$%()`\";
errorChar = isCharsInBag( s, badChar)
if (errorChar != \"\" )
{
report=report+\"请重新输入中文\\n\";
return false;
}
return true;
}
时间: 2024-09-23 17:10:18