This article explains how to use the validation capabilities of RadTextBox
The text in RadTextBox can be validated. The control doesn't do the validation automatically, but it can go to a different visual state if it knows that the text is valid, for example.
The new visual state can be applied with the ChangeValidationState method. It has two parameters. The first is the validation state, which is of type ValidationState and can have the following values:
- NotValidated - this is the default state when it is not clear whether the text is valid or not.
- Validating - this is the state when the validation logic is being executed.
- Valid - this is the state when the validation is completed and the text is valid.
- Invalid - this is the state for the control when the text is not valid.
The second parameter in the ChangeValidationState method is ValidationMessage
This is the message that will be displayed above the text box to notify the end user about the validation.
Here is an example of a text box for an email:
radTextBox.LostFocus += new RoutedEventHandler(radTextBox_LostFocus);
private void radTextBox_LostFocus(object sender, RoutedEventArgs e)
bool isValid = Validate(radTextBox.Text);
radTextBox.ChangeValidationState(ValidationState.Invalid, "Please enter a valid email!");
private bool Validate(string text)
Here is how the control will look in the different states: