2015-08-03 38 views
2

我需要確保一個人的密碼符合特定條件才能繼續創建其帳戶我想添加一個語句檢查',",以及,的應用是在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 
+0

使用正則表達式[(info)](http://www.regular-expressions.info/)[(usage)](http://stackoverflow.com/questions/6675920/using-classic-asp-for-正則表達式) - 在這方面它更有用。 – Paul

+0

謝謝你下次再看看,寧願只是現在添加一個聲明。 – Benswana

回答

2

你可以從字面上檢查他們:。

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將此用於字符串文字,因此當您需要在字符串文本中引用它時,必須將其轉義(通過使用其中的兩個)。

相關問題