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

countrymeister
countrymeister used Ask the Experts™
on
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, "^/[.!@#$%^&*]/*$")
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
IT Guru
Most Valuable Expert 2011
Commented:
Try this:
Dim bUppercase As Boolean = Regex.IsMatch(txtPassword.Text, "[A-Z]")
 Dim bNumeric As Boolean = Regex.IsMatch(txtPassword.Text, "\d")
 Dim bSpecial As Boolean = Regex.IsMatch(ItxtPassword.Text, "[.!@#$%^&*]")

Open in new window

Terry WoodsIT Guru
Most Valuable Expert 2011

Commented:
Or, all in one expression:
Dim bGoodPassword As Boolean = Regex.IsMatch(txtPassword.Text, "^(?=.*[A-Z])(?=.*\\d)(?=.*[.!@#$%^&*])")

Open in new window

Terry WoodsIT Guru
Most Valuable Expert 2011

Commented:
In my first post, I think you need to escape the backslash:
 Dim bNumeric As Boolean = Regex.IsMatch(txtPassword.Text, "\\d")
kaufmedGlanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
@TerryAtOpus
In my first post, I think you need to escape the backslash:
Not in VB  ; )

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial