网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的范文:

 

标题 验证字符串中是否包含有效字符
范文
    在常规输入表单的使用中时,经常会要求用户只能使用A~Z、a~z、0~9内的字符,那如何实现在服务
    器端的验证呢?
    下面是一个用于以上验证的函数:
    <%
    '**************************************
    '文件名: Asc.asp
    '描 述: '验证MyString是否含有有效字符A~Z、a~z和0~9
    '**************************************
    Function TestString (MyString)
    Dim TempStr, Length, Result, I, Char, Ascii
    TempStr = TRIM(MyString)
    Length = Len(TempStr)
    Result = False
    For I = 1 To Length
    Char = Mid(TempStr,I)
    Ascii = Asc(Char)
    '判断字符的ASCII值
    If 47 < Ascii < 58 Or 64 < Ascii < 91 Or 96 <Ascii <123 Then
    Result = True
    Exit For
    Else
    Result = False
    End If
    Next
    TestString = Result
    End Function
    %>
    该函数的调用方法如:
    TestString(MyString)
    如果MyString是要验证的字符串,则函数会返回一个Boolean值:True是指字符串在所有的Alpha
    值之内,False不是.
    具体用法举例:
    <%
    '**************************************
    '文件名: MySTring.asp
    '描 述: 验证MyString是否含有有效字符A~Z、a~z和0~9
    '**************************************
    dim str
    str = request.form("test")
    if TestString(str) then
    response.write "恭喜,字符串合法!"
    else
    response.write "里面有非法字符串!"
    end if
    Function TestString (MyString)
    Dim TempStr, Length, Result, I, Char, Ascii
    TempStr = TRIM(MyString)
    Length = Len(TempStr)
    Result = False
    For I = 1 To Length
    Char = Mid(TempStr,I)
    Ascii = Asc(Char)
    '判断字符的ASCII值
    If 47 < Ascii < 58 Or 64 < Ascii < 91 Or 96 <Ascii <123 Then
    Result = True
    Exit For
    Else
    Result = False
    End If
    Next
    TestString = Result
    End Function
    %>
    <form method="post">
    <input type="text" name="test">
    <input type="submit" value="submit">
    </form>
随便看

 

在线学习网范文大全提供好词好句、学习总结、工作总结、演讲稿等写作素材及范文模板,是学习及工作的有利工具。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/16 6:59:42