New to Telerik UI for Xamarin? Download free 30-day trial

How to use validation behaviors with RadEntry control


Product Version 2019.2 802.1
Product Entry for Xamarin


RadEntry supports the standard Xamarin.Forms behaviors in a similar way as the Xamarin.Forms Entry. You just need to create a Behavior class and apply it to its Behaviors property.


Below you can find a simple implementation of an email validation behavior applied to RadEntry control.

First, create the custom EmailValidatorBehavior class that inherits from Behavior<RadEntry> - the TextColor of the Entry is changed depending on whether the user has entered valid email:

public class EmailValidatorBehavior : Behavior<RadEntry>
    const string emailRegex = @"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +

    protected override void OnAttachedTo(RadEntry bindable)
        bindable.TextChanged += HandleTextChanged;

    void HandleTextChanged(object sender, TextChangedEventArgs e)
        bool IsValid = false;
        IsValid = (Regex.IsMatch(e.NewTextValue, emailRegex, RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(250)));
        ((RadEntry)sender).TextColor = IsValid ? Color.Black : Color.Red;

    protected override void OnDetachingFrom(RadEntry bindable)
        bindable.TextChanged -= HandleTextChanged;

Apply the above defined behavior to the RadEntry instance:

<telerikInput:RadEntry x:Name="entry" WatermarkText="Email" >
        <local:EmailValidatorBehavior x:Name="emailValidator"/>

You could learn more about behaviors in the following Xamarin blog post: Behaviors in Xamarin.Forms.

In this article