Skip to main content
.NET 6.0+

RuleRegularExpressionAttribute Class

Defines a validation rule that demands the target property match a specified pattern.

Namespace: DevExpress.Persistent.Validation

Assembly: DevExpress.Persistent.Base.v24.1.dll

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.

You can see examples of using the RuleRegularExpression and other validation attributes in the Validation section of the FeatureCenter demo. This demo is located in the %PUBLIC%\Documents\DevExpress Demos 24.1\Components\XAF\FeatureCenter.NETFramework.XPO folder, by default.

Inheritance

Object
Attribute
RuleBaseAttribute
RuleRegularExpressionAttribute
See Also