forms - 检测字符串中的引号 ("), single quote (' ) 和逗号

标签 forms vbscript asp-classic passwords

我需要确保某人的密码符合特定标准,然后他们才能继续创建帐户。我想添加一条语句检查 '",。该应用程序采用 VBScript 编写。这是我到目前为止所拥有的.我在网上找不到任何东西。

IsComplex = True

'Check Length
If Len(cPassword) < 8 Then
    IsComplex = False
End If

'Check for lowercase letters
HasLowerCase = False
For x = 97 to 122
    If Instr(4,cPassword,chr(x)) > 0 Then
        HasLowerCase = True
    End If
Next
If HasLowerCase = False Then
    IsComplex = False
    cForceChange = "E"
End If

'Check for uppercase letters
HasUpperCase = False
For x = 65 to 90
    If Instr(1,cPassword,chr(x)) > 0 Then
        HasUpperCase = True
    End If
Next
If HasUpperCase = False Then
    IsComplex = False
    cForceChange = "E"
End If

'Check for numbers
HasNumber = False
For x = 48 to 57
    If Instr(1,cPassword,chr(x)) > 0 Then
        HasNumber = True
        cForceChange = "E"
    End If
Next
If HasNumber = False Then
    IsComplex = False
    cForceChange = "E"
End If

最佳答案

您可以逐字检查它们:

If InStr(cPassword, "'")  > 0 Then  ' Single-quote found
If InStr(cPassword, """") > 0 Then  ' Double-quote found (need to use TWO quotes)
If InStr(cPassword, ",")  > 0 Then  ' Comma found

唯一棘手的是双引号 (")。由于 VBScript 将其用于字符串文字,因此当您需要在内部引用它时,必须对其进行转义(通过使用其中两个)字符串文字。

关于forms - 检测字符串中的引号 ("), single quote (' ) 和逗号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31785497/

相关文章:

forms - 提供没有网络界面的表单

forms - PlayFramework 2.x - 将错误消息形成/关联到元组的一个元素

jsp - JSP 形式的空字段是否为 null 或 ""?

macros - 导出Word审稿评论时,如何引用与评论相关的句子?

excel - 打开 excel 文件工作正常,但如果我通过 Windows 任务计划程序安排脚本,它不工作

xml - 如何使用 vbscript 删除 XML 文件中的节点?

asp.net - IIS 应用程序池 bin 与 *.vb

javascript - 当您提交表单时,单击的按钮是否也会发布?

asp-classic - 如何在经典 asp 中转换日期字符串

javascript - 如何使用经典 ASP 在服务器端包含 javascript 文件?