# ValidationRule

Namespace: **Wisej.Web**

Assembly: **Wisej.Framework** (4.0.0.0)

Represents a validation rule within an instance of the [Validation](/api/wisej.web/extenders/validation.md) extender.

{% tabs %}
{% tab title="C#" %}

```csharp
public class ValidationRule
```

{% endtab %}

{% tab title="VB.NET" %}

```visual-basic
Public Class ValidationRule
```

{% endtab %}
{% endtabs %}

## Constructors

### ![](/files/hsR4ok3152WyAf8J2C1u) ValidationRule()

Initializes a new instance of a [ValidationRule](/api/wisej.web/extenders/validation/wisej.web.validationrule.md) implementation.

### ![](/files/hsR4ok3152WyAf8J2C1u) ValidationRule(name, invalidMessage)

Initializes a new instance of a [ValidationRule](/api/wisej.web/extenders/validation/wisej.web.validationrule.md) implementation using the specified *name* and optional *invalidMessage* .

| Name               | Type                                                          | Description                                   |
| ------------------ | ------------------------------------------------------------- | --------------------------------------------- |
| **name**           | [String](https://docs.microsoft.com/dotnet/api/system.string) | Name of the validation rule.                  |
| **invalidMessage** | [String](https://docs.microsoft.com/dotnet/api/system.string) | Error message related to the validation rule. |

## Properties

### ![](/files/hsR4ok3152WyAf8J2C1u) Enabled

[Boolean](https://docs.microsoft.com/dotnet/api/system.boolean): Enables or disables the validation rule. <mark style="color:blue;background-color:green;">Since 3.2.7</mark> (Default: `True`)

### ![](/files/hsR4ok3152WyAf8J2C1u) ErrorProvider

[IErrorProvider](/api/wisej.web/interfaces/wisej.web.ierrorprovider.md): Returns or sets the control that displays the [InvalidMessage](#invalidmessage) string. (Default: `null`)

### ![](/files/hsR4ok3152WyAf8J2C1u) InvalidMessage

[String](https://docs.microsoft.com/dotnet/api/system.string): Returns or sets the error message for the validation rule. (Default: `null`)

### ![](/files/hsR4ok3152WyAf8J2C1u) Name

[String](https://docs.microsoft.com/dotnet/api/system.string): Returns or sets the name of the validation rule. (Default: `null`)

## Methods

### ![](/files/hsR4ok3152WyAf8J2C1u) OnControlCreated(control)

Invoked when the control associated with the validation rule is created and ready to be rendered on the client.

| Parameter   | Type                                         | Description            |
| ----------- | -------------------------------------------- | ---------------------- |
| **control** | [Control](/api/wisej.web/general/control.md) | Control being created. |

The [ControlCreated](/api/wisej.web/general/control.md#controlcreated) event is fired when the control is made visible the first time and it's ready to be displayed on the client browser; it's not fire when the control is constructed. Use this overload if your custom [ValidationRule](/api/wisej.web/extenders/validation/wisej.web.validationrule.md) needs to read or set properties on the control itself. i.e. set the [Filter](/api/wisej.web/editors/wisej.web.textbox.md#filter), or format strings.

### ![](/files/hsR4ok3152WyAf8J2C1u) OnValidated(control)

Invoke after the *control* has been validated successfully.

| Parameter   | Type                                         | Description                          |
| ----------- | -------------------------------------------- | ------------------------------------ |
| **control** | [Control](/api/wisej.web/general/control.md) | Control that validated successfully. |

### ![](/files/hsR4ok3152WyAf8J2C1u) OnValidating(control)

Invoked when the *control* is being validated.

| Parameter   | Type                                         | Description              |
| ----------- | -------------------------------------------- | ------------------------ |
| **control** | [Control](/api/wisej.web/general/control.md) | Control being validated. |

**Returns:** [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean). true if the validation is successful; otherwise false.

## Inherited By

| Name                                                                                                | Description                                                                                                                          |
| --------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| [RegexValidationRule](/api/wisej.web/extenders/validation/wisej.web.regexvalidationrule.md)         | Validates the control using a custom [Regex](https://docs.microsoft.com/dotnet/api/system.text.regularexpressions.regex) expression. |
| [RequiredValidationRule](/api/wisej.web/extenders/validation/wisej.web.requiredvalidationrule.md)   | Validates controls that cannot be left empty.                                                                                        |
| [TelephoneValidationRule](/api/wisej.web/extenders/validation/wisej.web.telephonevalidationrule.md) | Validates telephone numbers.                                                                                                         |
| [DecimalValidationRule](/api/wisej.web/extenders/validation/wisej.web.decimalvalidationrule.md)     | Validates decimal values.                                                                                                            |
| [CurrencyValidationRule](/api/wisej.web/extenders/validation/wisej.web.currencyvalidationrule.md)   | Validates currency values.                                                                                                           |
| [IntegerValidationRule](/api/wisej.web/extenders/validation/wisej.web.integervalidationrule.md)     | Validates long integer values.                                                                                                       |
| [EmailValidationRule](/api/wisej.web/extenders/validation/wisej.web.emailvalidationrule.md)         | Validates email addresses.                                                                                                           |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wisej.com/api/wisej.web/extenders/validation/wisej.web.validationrule.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
