Regular expression for password validation in .net

Following example show that how we can validate password with the help of Regular Expression that have following validation in and c# languages :

-Must be at least 10 characters
-Must contain at least one one lower case letter,
-One upper case letter,
-One digit and one special character
-Valid special characters are – @#$%^&+=

(Passwords like ‘asWE$21@ut’, WER@#%345ertO’ etc are the valid password entries according to following code.)


  1. Private Sub Button1_Click(ByVal Sender As Object, _
  2.                               ByVal e As System.EventArgs) Handles Button1.Click
  3.         Dim MatchNumberPattern As String = "^.*(?=.{10,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$"
  4.         If TextBox2.Text.Trim <> "" Then
  5.             If Not Regex.IsMatch(TextBox2.Text, MatchNumberPattern) Then
  6.                 MessageBox.Show("Password is not valid")
  7.             End If
  8.         End If
  9. End Sub


  1. private void Button1_Click(object Sender, System.EventArgs e)
  2. {
  3.  string MatchNumberPattern = "^.*(?=.{10,})(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$";
  4.  if (!string.IsNullOrEmpty(TextBox2.Text.Trim)) {
  5.   if (!Regex.IsMatch(TextBox2.Text, MatchNumberPattern)) {
  6.    MessageBox.Show("Password is not valid");
  7.   }
  8.  }
  9. }



I am developer have good knowledge of ver 05,08,10 and good hand in sql server.Proficient in Object Oriented Programming and javascript, jQuery. Achievements - Integrate Spotfire, appnexus API with sql server. Hobbies - Blogging ,Games, Movies ,Teaching,Keeping myself update with new technologies

You may also like...