RegularExpressionAttribute(String) 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 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
用來驗證資料欄位值的正則表達式。
例外狀況
pattern 是 null。
範例
以下範例說明如何將 應用 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