MaskedTextBox Upper Case Regex??

Editors for WPF Forum

Posted 14 years ago by Brette Esterbrooks
Version: 9.1.0506
Avatar
Hello,

First off thanks for providing a edit mask control suite. This is something that has been lacking for a long time. I am having an issue however with the MakedTextBox control. I using the following code to force correct entry of Canadian postal codes. For some reason however it allows the input of lower case characters. It seems to not be honoring the char classes I am using in my regex. Am I missing something?

<Editors:MaskedTextBox Name="txtZipCode"
Grid.Column="3"
MaskType="Regex"
Mask="[A-Z]\d[A-Z] \d[A-Z]\d"
Grid.Row="0"
HorizontalAlignment="Stretch"
Text="{Binding Path=CurrentAddress.ZipCode, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />


Thanks,
Brette

Comments (7)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Brette,

The MaskedTextBox is case-insenstive by default, so you'd need to set IsCaseSensitive to true to prevent lower case chars from being entered. Ideally, you should allow both upper and lower case characters and simply make them upper case in the OnTextChanging event. Since this makes input easier on your users :-)

Hope this helps.


Actipro Software Support

Posted 14 years ago by Brette Esterbrooks
Avatar
It seems odd to me that the default behavior would ignore my regular expression. What if I wanted the following aAa or AAaa etc. In fact I am not sure how you could even sure how it would be technically possible to ignore the upper case if you were really using a regex parser?

Can you please provide a sample of the OnTextChangingMethod.

Thanks,
Brette
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Brette,

If you need something like "aAa", then you can set the appropriate regular expression and set IsCaseSensitive to true. But in general that type of thing is harder for users to input, but the option is there when you need it.

We use an internal regular expression parser and DFA, but the .Net Regex class has an IgnoreCase option as well.

The "MaskedTextBox Filter Input" QuickStart shows how to force the text to uppercase.


Actipro Software Support

Posted 13 years ago by Glen
Avatar
This is a shameful implementation of a masked text box.

What if I want to allow users to enter text in either case, but force to upper case, but only certain characters as defined in my regular expression?

[A-Z][A-Z][A-Z][a-z][a-Z][0-9]

In order to implement this simple input mask on the actipro MaskedTextBox, I have to put in a lot of work, in which case I may as well have just used a standard .Net control.

Awful.
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Glen,

Thank you for the feature suggestion of automatically correcting the case as needed. We've implemented this feature for the next maintenance release.


Actipro Software Support

Posted 13 years ago by Pat Maneely - Software Engineering Manager, Cobham Aerospace
Avatar
I can't seem to figure out how to set the IsCaseSensitive property on a MaskedTextBox from XAML.

Here is my XAML.

<datagrideditors:DataGridMaskedTextColumn Header="Material" Mask="[0-9A-F]*"
Width="Auto" HeaderStyle="{StaticResource CenterAlignedColumnHeaderStyle}"
Binding="{Binding Material}">
</datagrideditors:DataGridMaskedTextColumn>


How would I set the IsCaseSensitive property? An example would be greatly appreciate :)


thanks
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Pat,

You'd probably have to create a class that inherits DataGridMaskedTextColumn and override its ApplyStandardValues method. First call the base implementation.

Then call something like this:
var element = targetElement as MaskedTextBox;
if (element != null)
    element.IsCaseSensitive = true;
We'll try to add a property to DataGridMaskedTextColumn in the future that is settable and then forwards that value down in ApplyStandardValues, similar to how Mask works.


Actipro Software Support

The latest build of this product (v24.1.2) was released 1 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.