Skip to main content

RepositoryItemTokenEdit.ValidateToken Event

Allows you to manually validate text entered by the user.

Namespace: DevExpress.XtraEditors.Repository

Assembly: DevExpress.XtraEditors.v24.1.dll

NuGet Package: DevExpress.Win.Navigation

Declaration

[DXCategory("Events")]
public event TokenEditValidateTokenEventHandler ValidateToken

Event Data

The ValidateToken event's data class is DevExpress.XtraEditors.TokenEditValidateTokenEventArgs.

Remarks

Important

The ValidateToken event does not raise if the Token Editor operates in data bound mode. In this instance, handle the ProcessNewValue event to validate user input.

The Token Editor raises the ValidateToken event when the editor control loses focus. The Token Editor splits the input text into blocks based on separator positions. Each block is then validated in the ValidateToken event handler.

Use the e.IsValid event parameter to indicate whether the processed block is valid. If the block passes validation (with e.IsValid set to true), it becomes a token (a clickable UI element that can display custom icons).

The following code snippet validates user input to accept only email addresses:

Validating email addresses in DevExpress Token Edit

using System.Text.RegularExpressions;

Regex MailRegex =
    new Regex(@"^[-a-z0-9!#$%&'*+/=?^_`{|}~]+(?:\.[-a-z0-9!#$%&'*+/=?^_`{|}~]+)*" +
    "@(?:[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?\\.)*" +
    "(?:aero|arpa|asia|biz|cat|com|coop|edu|gov|" +
    "info|int|jobs|mil|mobi|museum|name|net|org|pro|tel|travel|[a-z][a-z])$",
    RegexOptions.Compiled);

private void ValidateToken(object sender, TokenEditValidateTokenEventArgs e) {
    e.IsValid = MailRegex.IsMatch(e.Description);
}

Use e.Value and e.Description event parameters to read and modify the token’s value and description as needed.

Read the following help topic for additional information: Token Edit Control.

Note

In Manual mode (EditMode), the Token Editor raises the ValidateToken event only when the user types the text in the edit box. In TokenList mode, the ValidateToken event does not raise.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the ValidateToken event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also