用ASP怎么检测一个字符串为数字或字母??

来源:百度知道 编辑:UC知道 时间:2024/05/29 17:44:31
能否根据ASCII判断??

试试这段代码
function aa(str)
for i=1 to len(str)
if (asc(mid(str,i,1))>=48 and asc(mid(str,i,1))=<57) or (asc(mid(str,i,1))>=65 and asc(mid(str,i,1))=<90) or (asc(mid(str,i,1))>=97 and asc(mid(str,i,1))=<122) then
aa=true
else
aa=false
exit for
end if
next
end function
'使用方法说明:aa(你要检测的变量名)
如果变量中含有其它字符,则返回FALSE,如果没有包含其它字符,则返回true

循环遍历这个字符串单个单个的进行字符判断,用Char.isDigit()方法判断是否为数字,用isLetter()方法判断是否为字母,需要输入参数,你查查资料吧

使用IsNumeric()判断是否为数字,如果为真那就是数字,否则为字符串.

检测ASCII值的大小,汉字的ASCII值小于0