I'm trying to get validation working with the RadMaskedTextBox, I have found a few posts and an old example in your online help http://www.telerik.com/help/wpf/radmaskedinput-features-validation.html
The current help for the RadMaskedTextBox doesn't even talk about validation.
What I would like to do is have the outline around the RadMaskedTextBox turn red when something is wrong the data entered into the textbox.
Could you please send me a small example of this ?
The current help for the RadMaskedTextBox doesn't even talk about validation.
What I would like to do is have the outline around the RadMaskedTextBox turn red when something is wrong the data entered into the textbox.
Could you please send me a small example of this ?
3 Answers, 1 is accepted
0
Accepted
Hi Terry,
Please take a look at the sample code bellow.
I hope this helps.
Best wishes,
Kiril Stanoev
the Telerik team
Please take a look at the sample code bellow.
<
Window
x:Class
=
"WpfApplication1.MainWindow"
xmlns:sys
=
"clr-namespace:System;assembly=mscorlib"
xmlns:local
=
"clr-namespace:WpfApplication1"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
Title
=
"MainWindow"
Height
=
"350"
Width
=
"525"
>
<
Grid
>
<
telerik:RadMaskedTextBox
Width
=
"200"
Height
=
"30"
MaxLength
=
"10"
MaskType
=
"None"
>
<
telerik:RadMaskedTextBox.Value
>
<
Binding
Path
=
"Name"
UpdateSourceTrigger
=
"PropertyChanged"
NotifyOnValidationError
=
"True"
ValidatesOnExceptions
=
"True"
>
<
Binding.ValidationRules
>
<
local:RegexValidationRule
/>
</
Binding.ValidationRules
>
</
Binding
>
</
telerik:RadMaskedTextBox.Value
>
</
telerik:RadMaskedTextBox
>
</
Grid
>
</
Window
>
using
System.Globalization;
using
System.Windows;
using
System.Windows.Controls;
namespace
WpfApplication1
{
public
partial
class
MainWindow : Window
{
public
MainWindow()
{
InitializeComponent();
this
.DataContext =
new
DataItem();
}
}
public
class
DataItem
{
public
string
Name {
get
;
set
; }
}
public
class
NameValidationRule : ValidationRule
{
public
override
ValidationResult Validate(
object
value, CultureInfo ultureInfo)
{
if
(value.ToString().Length > 5)
{
return
new
ValidationResult(
false
,
"Error. String cannot be longer than 5 characters."
);
}
else
{
return
new
ValidationResult(
true
,
null
);
}
}
}
}
I hope this helps.
Best wishes,
Kiril Stanoev
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
terry
Top achievements
Rank 1
answered on 05 Mar 2011, 06:26 PM
Thanks Kiril
Your example was very helpful.
In the method Validate, there is error message "Error. String cannot be longer than 5 characters." When there is a validation error how can I get this error message displayed ?
I took the example from your previous post and turned it into a demo, but the error string is never displayed.
I looked through the Examples or Demo project that is included with the controls, at the Grid Validation example and when there is a validation error, at the top right corner of the masked textbox there is an area that if I hover with the mouse the error message will be displayed, how can I get that to work in the example that you provided me ?
Thanks for your help
Your example was very helpful.
In the method Validate, there is error message "Error. String cannot be longer than 5 characters." When there is a validation error how can I get this error message displayed ?
I took the example from your previous post and turned it into a demo, but the error string is never displayed.
I looked through the Examples or Demo project that is included with the controls, at the Grid Validation example and when there is a validation error, at the top right corner of the masked textbox there is an area that if I hover with the mouse the error message will be displayed, how can I get that to work in the example that you provided me ?
Thanks for your help
0
Hi terry,
You can find a possible approach for the desired behavior in the attached solution. It basically follows this article. However, we highly suggest you to use the new RadMaskedInput suite of controls. They will be officially released with the telerik Q1 2011 Release scheduled for the next week.
All the best,
Petar Mladenov
the Telerik team
You can find a possible approach for the desired behavior in the attached solution. It basically follows this article. However, we highly suggest you to use the new RadMaskedInput suite of controls. They will be officially released with the telerik Q1 2011 Release scheduled for the next week.
All the best,
Petar Mladenov
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!