title: vb.net password validation using regular expressions
body: <p>How does one call a function to validate a password which has been put into a textbox?</p>
  
  <pre><code>Function ValidatePassword(ByVal pwd As String, 
  Optional ByVal minLength As Integer = 8, 
  Optional ByVal numUpper As Integer = 2, 
  Optional ByVal numLower As Integer = 2, 
  Optional ByVal numNumbers As Integer = 2, 
  Optional ByVal numSpecial As Integer = 2) As Boolean
  
  ' Replace [A-Z] with \p{Lu}, to allow for Unicode uppercase letters.
  Dim upper As New System.Text.RegularExpressions.Regex("[A-Z]")
  Dim lower As New System.Text.RegularExpressions.Regex("[a-z]")
  Dim number As New System.Text.RegularExpressions.Regex("[0-9]")
  ' Special is "none of the above".
  Dim special As New System.Text.RegularExpressions.Regex("[^a-zA-Z0-9]")
  
  ' Check the length.
  If Len(pwd) &lt; minLength Then Return False
  ' Check for minimum number of occurrences.
  If upper.Matches(pwd).Count &lt; numUpper Then Return False
  If lower.Matches(pwd).Count &lt; numLower Then Return False
  If number.Matches(pwd).Count &lt; numNumbers Then Return False
  If special.Matches(pwd).Count &lt; numSpecial Then Return False
  
  ' Passed all checks.
  Return True
  End Function
  </code></pre>