Click here to Skip to main content
15,883,606 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to strenghten the password for a registration page and how to validate it in asp.net c#


I want some characters,numbers,Special characters,




XML
<td style="text-align: left; width: 90px;">
                                   Password
                               </td>
                               <td style="font-family: Verdana; font-size: medium; font-style: normal; text-align: left">
                                   <asp:TextBox ID="txtpassword" runat="server" Width="208px" ></asp:TextBox>
                                   <asp:RegularExpressionValidator ID="regpass" runat="server"
                                       ErrorMessage="RegularExpressionValidator" ControlToValidate="txtpassword"
                                       ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
                               </td>
Posted
Updated 2-Sep-12 21:17pm
v2

1 solution

Validating password with
-must be 8 characters including 1 uppercase letter, 1 special character & alphanumeric characters
(?=.*\d)        #   must contain at least one digit
(?=.*[A-Z])     #   must contain at least one uppercase character
(?=.*\W)        #   must contain at least one special symbol
   .            #   match anything with previous condition checking
{8,8}           #   length at least 8 characters and also maximum of 8

In one line:
((?=.*\d)(?=.*[A-Z])(?=.*\W).{8,8})

Sources:
* Password matching expression[^]
* Password Strength Validation with Regular Expressions[^]
* ASP.Net Regular Expression Validator to validate Minimum and Maximum Text Length[^]
 
Share this answer
 
Comments
Mohamed Mitwalli 3-Sep-12 2:21am    
5+
Prasad_Kulkarni 3-Sep-12 2:32am    
Thank you Mohamed!
Shibiny 3-Sep-12 2:31am    
I Used your code like this:

<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
ErrorMessage="RegularExpressionValidator" ControlToValidate="txtpassword"
ValidationExpression="((?=.*\d)(?=.*[A-Z])(?=.*\W).{8,8})">
It Worked fine,But data after error message,Entered data saved to database,how to prevent this
Prasad_Kulkarni 3-Sep-12 2:33am    
Use retrun, if error occurs.
Shibiny 3-Sep-12 3:00am    
How to do this

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900