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 数据字段。 如果验证失败,示例中的代码将显示动态数据提供的验证错误消息。

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

适用于