Zero-required character mask bug

Editors for WPF Forum

Posted 12 years ago by Brandon Bonds
Version: 11.1.0543
Platform: .NET 4.0
Environment: Windows 7 (64-bit)
Avatar
I'm using the MaskedTextBox in my view-model code to validate text entered a different way than through the MaskedTextBox. To do this, I am creating an instance of MaskedTextBox, setting the Mask and Text properties, and checking the IsMatched property.

But I'm finding that "IsMatched" is true for any mask that allows zero characters, regardless of the input. For instance, the pattern "1*" will match "", "1", "11", etc., but also other strings like "abc".

The same applies when the mask is simply "", or when it is negative (like "[^0-9]*"), or even when it is a complex mask like "1*2*3*". I've also tried it with the mask "1{0,2}", which accepts anything (including "111", which is very unexpected).

This behavior does not occur if you put a forced character in the mask. So a mask "a1*" only accepts strings like "a", "a1", "a11", etc., and does not accept strings like "abc" (as expected). Masks like "1+" also work as expected.

So, the behavior seems to be inconsistent between nullable masks and non-nullable masks. The behavior is also inconsistent with the UI, which does not display invalid text even if IsMatched is true.

On another note, I found another bug in that the mask "\d{5}|1*" will only accept 5 digits in the UI, even if they are all "1"s. The prompt character comes up for the 6th "1", but I am not allowed to enter it.

Comments (3)

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Brandon,

Thanks for reporting this issue. I'm seeing a bit different behavior with the latest build, but it was still not correct. We've correct this for the next maintenance release so the regular expressions you've listed will work as expected.


Actipro Software Support

Posted 12 years ago by Brandon Bonds
Avatar
Thanks for the quick response!

I noticed something else related to this. I cannot bind to the IsMatched property in XAML. My use case is that I have a dialog with a masked text box, and I want to disable the OK button when the entered text doesn't validate according to the mask.

Is this possible (or have I overlooked something)? I've tried using a OneWayToSource binding, binding to a property on my view-model, but I still cannot compile due to an error stating that the IsMatched property "does not have an accessible set accessor". I suspect that's actually a WPF bug, since I'm attempting to bind to the getter and not the setter... so I'm not even sure how it can be fixed.
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Brandon,

Sorry, but WPF will not allow you to set a binding on read-only dependency properties (even if it's OneWayToSource). You will probably have to attach to the IsMatchedChanged event, and update your view-model there.

Or you may be able to use a third-party solution, such as this.


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.