欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

如何验证字符串是否包含有效字符?

程序员文章站 2023-01-25 18:14:52
<%function teststring(somestring)tempstring = trim(so...

<%
function teststring(somestring)
tempstring = trim(somestring)
tempstring_length = len(tempstring)
tempstring_ok = true
for tempstring_pos = 1 to tempstring_length
  tempstring_char = mid(tempstring,tempstring_pos)
  tempstring_char_ansi = asc(tempstring_char)
  if tempstring_char_ansi > 47 and tempstring_char_ansi < 123 then

' ansi字符中:a-z 65-90,a-z97-122,0-948-57
    if tempstring_char_ansi > 57 and tempstring_char_ansi < 65 then
    tempstring_ok = false
    exit for
    end if
    if tempstring_char_ansi > 90 and tempstring_char_ansi < 97 then
    tempstring_ok = false
    exit for
    end if
  else
    tempstring_ok = false
    exit for
  end if
next
teststring = tempstring_ok
end function
%>