RuleRegularExpressionAttribute Class

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

Namespace: DevExpress.Persistent.Validation

Assembly: DevExpress.Persistent.Base.v18.2.dll

Declaration

[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class RuleRegularExpressionAttribute :
    RuleBaseAttribute,
    _Attribute,
    IRuleBaseAttribute,
    IRuleRegularExpressionProperties,
    IRulePropertyValueProperties,
    IRuleCollectionPropertyProperties,
    IRuleBaseProperties
<AttributeUsage(AttributeTargets.Property, AllowMultiple:=True)>
Public Class RuleRegularExpressionAttribute
    Inherits RuleBaseAttribute
    Implements _Attribute,
               IRuleBaseAttribute,
               IRuleRegularExpressionProperties,
               IRulePropertyValueProperties,
               IRuleCollectionPropertyProperties,
               IRuleBaseProperties

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.

//...
private string email;
[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 string Email {
   get { return email; }
   set { SetPropertyValue("Email", ref email, value); }
}
//...

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 in the Application Model 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 18.2\Components\eXpressApp Framework\FeatureCenter folder, by default.

Inheritance

Object
Attribute
RuleBaseAttribute
RuleRegularExpressionAttribute
See Also