This documentation is archived and is not being maintained.

CreateUserWizard.PasswordRegularExpression Property

Gets or sets a regular expression used to validate the provided password.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public virtual string PasswordRegularExpression { get; set; }
<asp:CreateUserWizard PasswordRegularExpression="String" />

Property Value

Type: System.String
A string containing the regular expression used to validate the provided password. The default value is an empty string ("").

Use the PasswordRegularExpression property to define the requirements for passwords used to validate users on your Web site. A common use is to make sure that a user has included symbols other than letters in a password to make it harder for attackers to guess a password. The regular expression is used in addition to any restrictions placed on the password by the membership provider specified in the MembershipProvider property. If the membership provider rejects the password for any reason, the text contained in the InvalidPasswordErrorMessage property is displayed.

If the password entered does not pass the regular expression, the error message contained in the PasswordRegularExpressionErrorMessage property is displayed to the user.

The following code example uses the PasswordRegularExpression property to define a regular expression that checks passwords to ensure that they:

  • Are longer than seven characters.

  • Contain at least one digit.

  • Contain at least one special (non-alphanumeric) character.

If the password entered by the user does not meet these criteria, the text contained in the PasswordRegularExpressionErrorMessage property is displayed to the user.

<%@ page language="C#"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>CreateUserWizard.PasswordRegularExpression sample</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:createuserwizard id="Createuserwizard1" runat="server" 
        passwordregularexpression='@\"(?:.{7,})(?=(.*\d){1,})(?=(.*\W){1,})'
        passwordregularexpressionerrormessage="Your password must be 7 characters long, and contain at least one number and one special character.">
      </asp:createuserwizard>
    </div>
    </form>
</body>
</html>

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Show: