RuleRegularExpressionAttribute Class
Defines a validation rule that demands the target property match a specified pattern.
Namespace: DevExpress.Persistent.Validation
Assembly: DevExpress.Persistent.Base.v25.2.dll
NuGet Package: DevExpress.Persistent.Base
Declaration
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class RuleRegularExpressionAttribute :
RuleBaseAttribute,
IRuleRegularExpressionProperties,
IRulePropertyValueProperties,
IRuleCollectionPropertyProperties,
IRuleBaseProperties
Remarks
Apply this attribute to a business class string property to define a validation rule that will check whether this property’s value matches a specified regular expression. Use the pattern parameter to specify the regular expression that the property must match. In addition, use the common parameters that are inherited from the RuleBaseAttribute class.
[RuleRegularExpression("",DefaultContexts.Save,
@"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$")]
public virtual string Email { get; set; }
// Make sure that you use options.UseChangeTrackingProxies() in your DbContext settings.
The rule generated by the RuleRegularExpressionAttribute will be loaded to the Application Model‘s IModelValidationRules node. So, you can customize this rule via the Model Editor. In addition, you can create new rules in the Model Editor as well. This is helpful when you need to add a rule to a property which is implemented in a base class provided by a third party library. For details, refer to the Implement Property Value Validation topic.
Tip
You can find examples of this functionality in the MainDemo demo included with XAF. The demo illustrates various XAF features (including RuleRegularExpression and other validation attributes) and is located in the %PUBLIC%\Documents\DevExpress Demos 25.2\Components\XAF\MainDemo.NET.EFCore folder.