ChangePassword.NewPasswordRegularExpressionErrorMessage 属性
定义
获取或设置当所输入的密码不符合 NewPasswordRegularExpression 属性中定义的正则表达式验证条件时显示的错误消息。Gets or sets the error message that is shown when the password entered does not pass the regular expression criteria defined in the NewPasswordRegularExpression property.
public:
virtual property System::String ^ NewPasswordRegularExpressionErrorMessage { System::String ^ get(); void set(System::String ^ value); };
public virtual string NewPasswordRegularExpressionErrorMessage { get; set; }
member this.NewPasswordRegularExpressionErrorMessage : string with get, set
Public Overridable Property NewPasswordRegularExpressionErrorMessage As String
属性值
当所输入的密码不符合 NewPasswordRegularExpression 属性中定义的正则表达式验证条件时显示的错误消息。The error message shown when the password entered does not pass the regular expression defined in the NewPasswordRegularExpression. 默认值为 Empty。The default is Empty.
示例
下面的代码示例演示如何设置 NewPasswordRegularExpression 属性以定义用于检查密码的正则表达式,以确保它们符合以下条件:The following code example shows how to set the NewPasswordRegularExpression property to define a regular expression that checks passwords to ensure that they meet the following criteria:
超过6个字符。Are greater than six characters.
包含至少一个数字。Contain at least one digit.
包含至少一个特殊 (非字母数字) 字符。Contain at least one special (non-alphanumeric) character.
属性中包含的密码要求 PasswordHintText 将显示给用户。The password requirements contained in the PasswordHintText property are displayed to the user.
如果用户输入的密码不符合条件,则 NewPasswordRegularExpressionErrorMessage 会向用户显示该属性中包含的文本。If the password entered by the user does not meet the criteria, the text contained in the NewPasswordRegularExpressionErrorMessage property is displayed to the user. 如果未输入新密码,则 NewPasswordRequiredErrorMessage 会向用户显示该属性中包含的文本。If a new password is not entered, the text contained in the NewPasswordRequiredErrorMessage property is displayed to the user.
备注
新密码还必须满足、和属性中的 成员资格提供程序 所设置的最低要求 MinRequiredPasswordLength MinRequiredNonAlphanumericCharacters PasswordStrengthRegularExpression 。The new password must also meet the minimum requirements set by the membership provider in the MinRequiredPasswordLength, MinRequiredNonAlphanumericCharacters, and PasswordStrengthRegularExpression properties. 如果密码不符合这些要求,则 ChangePasswordError 会引发事件。If the password does not meet these requirements, the ChangePasswordError event is raised.
<%@ 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>Change Password with Validation</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:changepassword id="ChangePassword1" runat="server"
PasswordHintText =
"Please enter a password at least 7 characters long,
containing a number and one special character."
NewPasswordRegularExpression =
'@\"(?=.{7,})(?=(.*\d){1,})(?=(.*\W){1,})'
NewPasswordRegularExpressionErrorMessage =
"Error: Your password must be at least 7 characters long,
and contain at least one number and one special character." >
</asp:changepassword>
</div>
</form>
</body>
</html>
<%@ page language="VB"%>
<!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>Change Password with Validation</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:changepassword id="ChangePassword1" runat="server"
PasswordHintText = "Please enter a password at least 7 characters long, containing a number and one special character."
NewPasswordRegularExpression = '@\"(?=.{7,})(?=(.*\d){1,})(?=(.*\W){1,})'
NewPasswordRegularExpressionErrorMessage = "Your password must be at least 7 characters long, and contain at least one number and one special character.">
</asp:changepassword>
</div>
</form>
</body>
</html>
注解
使用 NewPasswordRegularExpressionErrorMessage 属性可通知用户输入的密码未通过属性中定义的正则表达式 NewPasswordRegularExpression 。Use the NewPasswordRegularExpressionErrorMessage property to inform the user that the password entered does not pass the regular expression defined in the NewPasswordRegularExpression property.
与 NewPasswordRegularExpressionErrorMessage 可以在数据存储级别配置的密码强制无关。The NewPasswordRegularExpressionErrorMessage is not related to the password enforcement that can be configured at the data store level. 新密码必须满足、和属性中的 成员资格提供程序 所设置的最低要求 MinRequiredPasswordLength MinRequiredNonAlphanumericCharacters PasswordStrengthRegularExpression 。The new password must meet the minimum requirements set by the membership provider in the MinRequiredPasswordLength, MinRequiredNonAlphanumericCharacters, and PasswordStrengthRegularExpression properties. 如果密码不符合这些要求,则 ChangePasswordError 会引发事件。If the password does not meet these requirements, the ChangePasswordError event is raised.
适用于
另请参阅
- NewPassword
- NewPasswordLabelText
- NewPasswordRegularExpression
- NewPasswordRequiredErrorMessage
- ASP.NET 登录控件概述ASP.NET Login Controls Overview
- 自定义 ASP.NET 登录控件的外观和行为Customizing Appearance and Behavior of the ASP.NET Login Controls
- ASP.NET Web 服务器控件模板ASP.NET Web Server Controls Templates
- 如何:向匿名用户和已登录的用户显示不同的信息How to: Display Different Information to Anonymous and Logged In Users
- 网站管理工具的 "安全" 选项卡Web Site Administration Tool Security Tab