ChangePassword.NewPasswordRegularExpressionErrorMessage 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
當輸入的密碼未通過屬性中定義 NewPasswordRegularExpression 的正則表達式標準時,會顯示錯誤訊息。
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. 預設值為 Empty。
範例
以下程式碼範例說明如何設定 NewPasswordRegularExpression 屬性以定義一個正則表達式,檢查密碼以確保符合以下條件:
大於六個字元。
至少包含一個數字。
至少包含一個特殊(非字母數字)字元。
該屬性中包含的 PasswordHintText 密碼要求會顯示給使用者。
若使用者輸入的密碼不符合條件,該屬性中的文字 NewPasswordRegularExpressionErrorMessage 會顯示給使用者。 若未輸入新密碼,該屬性中的 NewPasswordRequiredErrorMessage 文字會顯示給使用者。
Note
新密碼也必須符合會員提供者MinRequiredPasswordLength在 、 MinRequiredNonAlphanumericCharacters及PasswordStrengthRegularExpression屬性中設定的最低要求。 若密碼不符合這些條件,事件 ChangePasswordError 將被觸發。
<%@ 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 屬性中定義的正規表達式。
這 NewPasswordRegularExpressionErrorMessage 與可在資料儲存層級設定的密碼強制無關。 新密碼必須符合會員提供者MinRequiredPasswordLength在 、 MinRequiredNonAlphanumericCharacters及PasswordStrengthRegularExpression屬性中設定的最低要求。 若密碼不符合這些條件,事件 ChangePasswordError 將被觸發。