Validation through custom Regular Expressions

One of the main features that RadMaskedInput supports is validation through a custom regular expression. You can define a input pattern of your choice and set it to the Mask property of the control. In order to use the validation through regular expressions, you should set the MaskType to Regex.

Custom Regex Example

MaskedInput with custom RegEx validation

<telerik:RadMaskedInput MaskType="Regex"
                        InvalidInputErrorText="Invalid date format!"
                        ErrorColor="Red"
                        WatermarkText="Enter Date"
                        Mask="^[0-9]{4}\/(30|31|[0-2]{0,1}[0-9]{1})\/(10|11|12|[0-9]{1})$"/>

Mask Extensions

The static class Telerik.XamarinForms.Input.MaskedInput.MaskExtensions contains two static regular expressions which you can directly use for validation when the MaskType is Regex:

  • IP: "^(([1-9]?\d|1\d\d|2[0-5][0-5]|2[0-4]\d)\.){3}([1-9]?\d|1\d\d|2[0-5][0-5]|2[0-4]\d)$"
  • Email: "^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$"

Built-in Regex Example

Validation using the MaskExtensions class

<telerik:RadMaskedInput MaskType="Regex"
                        InvalidInputErrorText="Invalid E-Mail format!"
                        ErrorColor="Red"
                        WatermarkText="Enter E-mail"
                        Mask="{x:Static extensions:MaskExtensions.Email}"/>

Where the following namespace is used:

xmlns:extensions="clr-namespace:Telerik.XamarinForms.Input.MaskedInput;assembly=Telerik.XamarinForms.Input"

See Also