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.)


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


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

Author: Pavan

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