Share via


ChangePassword.NewPasswordRequiredErrorMessage 屬性

定義

取得或設定錯誤訊息,其顯示於當使用者將 [新密碼] 文字方塊保留為空白時。

public:
 virtual property System::String ^ NewPasswordRequiredErrorMessage { System::String ^ get(); void set(System::String ^ value); };
public virtual string NewPasswordRequiredErrorMessage { get; set; }
member this.NewPasswordRequiredErrorMessage : string with get, set
Public Overridable Property NewPasswordRequiredErrorMessage As String

屬性值

當使用者將 [新密碼] 文字方塊保留為空白時,所顯示的錯誤訊息。 預設值為 [必須提供新密碼]。

範例

下列程式碼範例示範如何設定 NewPasswordRegularExpression 屬性來定義正則運算式,以檢查密碼以確保它們符合下列準則:

  • 大於六個字元。

  • 至少包含一位數。

  • 至少包含一個特殊 (非英數位元) 字元。

屬性中包含的 PasswordHintText 密碼需求會顯示給使用者。

如果使用者輸入的密碼不符合準則,則會向使用者顯示 屬性中包含的 NewPasswordRegularExpressionErrorMessage 文字。 如果未輸入新密碼,則會向使用者顯示 屬性中包含的 NewPasswordRequiredErrorMessage 文字。

注意

新的密碼也必須符合 、 MinRequiredNonAlphanumericCharactersPasswordStrengthRegularExpression 屬性中 MinRequiredPasswordLength成員資格提供者所設定的最低需求。 如果密碼不符合這些需求,就會 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>

備註

設定時,這個屬性的值可以使用設計工具自動儲存到資源檔。 如需詳細資訊,請參閱 LocalizableAttribute全球化和當地語系化

適用於

另請參閱