|
52 | 52 | <remarks>
|
53 | 53 | <format type="text/markdown"><![CDATA[
|
54 | 54 |
|
55 |
| -## Remarks |
56 |
| - You apply the RegularExpressionAttribute attribute to a property when you need to validate values for the property against a regular expression. The regular expression enables you to specify very precisely the format of valid values. The Pattern property contains the regular expression. If the value of the property is null or an empty string (""), the value automatically passes validation for the RegularExpressionAttribute attribute. To validate that the value is not `null` or an empty string, use the **RequiredAttribute** attribute. |
| 55 | +## Remarks |
57 | 56 |
|
58 |
| -The regular expression searches for an exact match, not using `^` before and `$` at the end of the pattern produces the same results as using it. For a search hit, prepend and append the pattern with `.*`. |
59 |
| - |
60 |
| - |
61 |
| - |
62 |
| -## Examples |
63 |
| - The following example shows how to use the <xref:System.ComponentModel.DataAnnotations.RegularExpressionAttribute> attribute to validate the FirstName and LastName data fields. The regular expression allows up to 40 uppercase and lowercase characters. The example performs the following tasks: |
64 |
| - |
65 |
| -- Implements a metadata partial class and the associated metadata class. |
66 |
| - |
67 |
| -- In the associated metadata class, applies the <xref:System.ComponentModel.DataAnnotations.RegularExpressionAttribute> attribute to the FirstName and LastName data fields, specifying the pattern and custom error messages. |
| 57 | +You apply the RegularExpressionAttribute attribute to a property when you need to validate values for the property against a regular expression. The regular expression enables you to specify very precisely the format of valid values. The Pattern property contains the regular expression. If the value of the property is null or an empty string (""), the value automatically passes validation for the RegularExpressionAttribute attribute. To validate that the value is not `null` or an empty string, use the **RequiredAttribute** attribute. |
| 58 | +
|
| 59 | +The regular expression searches for an exact match, not using `^` before and `$` at the end of the pattern produces the same results as using it. For a search hit, prepend and append the pattern with `.*`. |
| 60 | +
|
| 61 | +## Examples |
| 62 | +
|
| 63 | +The following example shows how to use the <xref:System.ComponentModel.DataAnnotations.RegularExpressionAttribute> attribute to validate the FirstName and LastName data fields. The regular expression allows up to 40 uppercase and lowercase characters. The example performs the following tasks: |
68 | 64 |
|
69 |
| - :::code language="csharp" source="~/snippets/csharp/VS_Snippets_WebNet/System.ComponentModel.DataAnnotations.RegularExpressionAttribute/CS/Customer.cs" id="Snippet1"::: |
70 |
| - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_WebNet/System.ComponentModel.DataAnnotations.RegularExpressionAttribute/VB/Customer.vb" id="Snippet1"::: |
| 65 | +- Implements a metadata partial class and the associated metadata class. |
| 66 | +- In the associated metadata class, applies the <xref:System.ComponentModel.DataAnnotations.RegularExpressionAttribute> attribute to the FirstName and LastName data fields, specifying the pattern and custom error messages. |
| 67 | +
|
| 68 | +:::code language="csharp" source="~/snippets/csharp/VS_Snippets_WebNet/System.ComponentModel.DataAnnotations.RegularExpressionAttribute/CS/Customer.cs" id="Snippet1"::: |
| 69 | +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_WebNet/System.ComponentModel.DataAnnotations.RegularExpressionAttribute/VB/Customer.vb" id="Snippet1"::: |
71 | 70 |
|
72 | 71 | ]]></format>
|
73 | 72 | </remarks>
|
| 73 | + <related type="Article" href="https://learn.microsoft.com/dotnet/standard/base-types/regular-expressions">.NET regular expressions</related> |
74 | 74 | </Docs>
|
75 | 75 | <Members>
|
76 | 76 | <Member MemberName=".ctor">
|
|
0 commit comments