RegularExpressionAttribute(String) 建構函式

定義

初始化 RegularExpressionAttribute 類別的新執行個體。

public:
 RegularExpressionAttribute(System::String ^ pattern);
public RegularExpressionAttribute(string pattern);
new System.ComponentModel.DataAnnotations.RegularExpressionAttribute : string -> System.ComponentModel.DataAnnotations.RegularExpressionAttribute
Public Sub New (pattern As String)

參數

pattern
String

用來驗證資料欄位值的正則表達式。

例外狀況

patternnull

範例

以下範例說明如何將 應用 RegularExpressionAttribute 於資料欄位。 若驗證失敗,範例中的程式碼會顯示 Dynamic Data 提供的驗證錯誤訊息。

// Allow up to 40 uppercase and lowercase 
// characters. Use standard error.
[RegularExpression(@"^[a-zA-Z''-'\s]{1,40}$")]
public object LastName;
' Allow up to 40 uppercase and lowercase 
' characters. Use standard error.
<RegularExpression("^[a-zA-Z''-'\s]{1,40}$")> _
Public LastName As Object

適用於