RegularExpressionAttribute(String) Konstruktor

Definicja

Inicjuje nowe wystąpienie klasy 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)

Parametry

pattern
String

Wyrażenie regularne używane do weryfikowania wartości pola danych.

Wyjątki

pattern to null.

Przykłady

W poniższym przykładzie pokazano, jak zastosować element RegularExpressionAttribute do pola danych. Jeśli walidacja nie powiedzie się, kod w przykładzie wyświetla komunikat o błędzie weryfikacji dostarczany przez dane dynamiczne.

// 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

Dotyczy