Problem

MaskedTextBox not handling non-matching text updates correctly

Posted 8 months ago by Avatar Ryan Courreges

Here's an example to illustrate the issue I found. Using a MaskedTextBox with the following mask:

[^0-9\s][^\s]{0,29}

so the input can't start with a number or whitespace and the rest of the value can't contain whitespace up to a total of 30 characters. This is great if you are typing from the beginning or appending to the end.

However, if the user attempts to input a space into the middle of the value somewhere, e.g., attempt to change "myValue" to "my Value", debugging the code shows me that the call to match matches the text up to the invalid character and gets rid of everything after, leaving me with "my". That's all fine and dandy and the matcher is just doing what it's told. 

Now to fix this to behave how any input should behave, just block that input and leave the original value intact, I would need to use the begin and end anchors so my mask would become:

^[^0-9\s][^\s]{0,29}$

The problem is, the implementation doesn't support these Regex elements.

 

So, the code should be updated to have a property to set it to match the whole string to give the proper behavior or the begin and end anchors need to be supported which would accomplish the same thing. (There may also be some regex kung fu that could be applied, but I'm not a regex expert). Is this something that could be tackled in an upcoming release? Or has it already been fixed in 663 or 664?


Comments (3)

Posted 8 months ago by Actipro Software Support - Cleveland, OH, USA

Hi Ryan,

Thanks for writing about this scenario.  It's a bit tricky to block some of this since we only know the old/new text string and selection.  So we sometimes have to make assumptions on what the user is doing only based on those values.  I think we were able to add some criteria that will block the input if the user appears to be adding text with no selection but the match gets trimmed at the original selection start.  That seems to resolve this issue.  Would you like to try a preview build to help test it out?


Actipro Software Support
Posted 8 months ago by Ryan Courreges

I can see that being tricky. Yes, I'd love to try out a preview build.

Posted 8 months ago by Actipro Software Support - Cleveland, OH, USA

Hi Ryan,

Please write our support address and mention this thread and I'll send you a URL.


Actipro Software Support
Information The latest build of this product (2018.1 build 0672) was released 2 months ago, which was after the last post in this thread.

Add a Comment

Please log in to a validated account to post comments.