This is a migrated thread and some comments may be shown as answers.

MaskedTextInput Validation Problem

3 Answers 256 Views
MaskedInput (Numeric, DateTime, Text, Currency)
This is a migrated thread and some comments may be shown as answers.
Christopher
Top achievements
Rank 1
Christopher asked on 29 May 2015, 02:46 PM

I have a RadMaskedTextInput Box that I have validated in the backend as follows.

//Phone Number
[RegularExpression(@"^\d{10}$")]
public string PhoneNumber
{
    get { return _phoneNumber; }
    set
    {
        double.TryParse(value, out temp);
        if (_phoneNumber != value)
        {
            Validator.ValidateProperty(value,
                new ValidationContext(this, null, null)
                {
                    MemberName = "PhoneNumber"
                });
            _phoneNumber = value;
            OnPropertyChanged("PhoneNumber");
        }
    }
}

The xaml for the object is as follows:

<!-- Phone Number -->
<telerik:RadMaskedTextInput Margin="2" BorderBrush="LightGray"
                                IsClearButtonVisible="False"
                                Mask="(###) ###-####"
                                UpdateValueEvent="PropertyChanged"
                                TextMode="PlainText"
                                Value="{Binding Path=PhoneNumber,
                                                Mode=TwoWay,
                                                NotifyOnValidationError=True,
                                                ValidatesOnExceptions=True,
                                                UpdateSourceTrigger=PropertyChanged}">

This does not have the expected behavior.

What I want is that when the user does not have a valid 10 digit phone number then set the validation flag that the number is incorrect.

While it may be left blank, as soon as they start typing I want it to show a red box until only 10 digits are present.

3 Answers, 1 is accepted

Sort by
0
Milena
Telerik team
answered on 01 Jun 2015, 01:04 PM
Hello Christopher,

Thank you for the code-snippet provided.

So, to achieve this you should set AllowInvalidValues property of the MaskedTextInput to true: 
<telerik:RadMaskedTextInput   AllowInvalidValues="True" .../>

This ensures that the Setter of the property will be fired even if the DataAnnotaion Validation does not succeed - in your case the error message will be shown when the users start typing until they entered all 10 digits.

I hope this helps.

Regards,
Milena
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Christopher
Top achievements
Rank 1
answered on 01 Jun 2015, 01:17 PM
That worked perfectly. Thank you very much! I attempted to find documentation for every Property within the Telerik WPF controls but was unable to.
0
Milena
Telerik team
answered on 02 Jun 2015, 06:37 AM
Hi Christopher,

I'm glad that the solution works for your scenario.

About the resources - in our online documentation you can find more about the Validation and the MaskedInput control and also you can take a look at our API Reference if you are interested.

I hope this will get you started.

Regards,
Milena
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
MaskedInput (Numeric, DateTime, Text, Currency)
Asked by
Christopher
Top achievements
Rank 1
Answers by
Milena
Telerik team
Christopher
Top achievements
Rank 1
Share this question
or