Reputation: 4663
I am score a password based on various features, but I don't believe my RegEx is correct:
If Regex.IsMatch(password, "/\d+/", RegexOptions.ECMAScript) Then
'Contains a number
score += 1
End If
If Regex.IsMatch(password, "/[a-z]/", RegexOptions.ECMAScript) Then
'Contains a lowercase letter
score += 1
End If
If Regex.IsMatch(password, "/[A-Z]/", RegexOptions.ECMAScript) Then
'Contains an uppercase letter
score += 1
End If
If Regex.IsMatch(password, "/.[!,@,#,$,%,^,&,*,?,_,~,-,£,(,)]/", RegexOptions.ECMAScript) Then
'Contains special character
score += 2
End If
How do I fix this? I believe these are formatted for C# not VB.NET.
Upvotes: 0
Views: 779
Reputation: 888107
The .Net Regex class takes the raw text of the regular expression.
You should not wrap it in /
characters; those simply match the literal text /
.
Some other notes:
RegexOptions.ECMAScript
Regex
instances instead of re-parsing each regex every time.Upvotes: 1