Posted 13 years ago
by Brandon Bonds
Version: 11.1.0543
Platform: .NET 4.0
Environment: Windows 7 (64-bit)
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.
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.