检测字符串中的引号 (")、单引号 (') 和逗号

Detect quote ("), single quote (') and comma in string

我需要确保一个人的密码符合特定条件,然后他们才能继续创建他们的帐户。我想添加一个检查 '", 的语句。该应用程序是在 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 将它用于字符串文字,因此当您需要在字符串文字中引用它时,您必须将其转义(通过使用其中两个)。