Link to home
Start Free TrialLog in
Avatar of countrymeister
countrymeister

asked on

Reqular expression in vb.net to check content of password field

I have a password field I need a regular expression to check if my filed has atleast one upper case letter ,atleast  one number andat least  one special character, tried this which does not work

   Dim bUppercase As Boolean = Regex.IsMatch(txtPassword.Text, "^/[A-Z]/*$")
        Dim bNumeric As Boolean = Regex.IsMatch(txtPassword.Text, "^/[0-9]/*$")
        Dim bSpecial As Boolean = Regex.IsMatch(ItxtPassword.Text, "^/[.!@#$%^&*]/*$")
ASKER CERTIFIED SOLUTION
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or, all in one expression:
Dim bGoodPassword As Boolean = Regex.IsMatch(txtPassword.Text, "^(?=.*[A-Z])(?=.*\\d)(?=.*[.!@#$%^&*])")

Open in new window

In my first post, I think you need to escape the backslash:
 Dim bNumeric As Boolean = Regex.IsMatch(txtPassword.Text, "\\d")
@TerryAtOpus
In my first post, I think you need to escape the backslash:
Not in VB  ; )