MaskedTextBox "Unformatted" text property?

Editors for WPF Forum

Posted 12 years ago by Brad Salmon
Version: 12.2.0570
Avatar

Is there a property or way to obtain the text of a MaskedTextBox without the mask applied?  For example, if I have a phone # field and the mask is "(\d\d\d) \d\d\d-\d\d\d\d" I want to be able to get the data that was entered without the mask like "5551234567".  I then want to be able to set the text of the MaskedTextBox to "5551234567" and have it display with the mask as "(555) 123-4567".  The reason is because we want to store the data without any masking/formatting applied so that if the client wants/needs to change the formatting they can without having to go through and scrub millions or records in the database.  I know that some other vendor's masked controls support this so I'm hoping I am just missing something and it can be done with Actipro controls.

 

- Brad

Comments (7)

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

Hi Brad,

The way our MaskedTextBox works is that it only stores the displayed text you see, and uses a regular expression engine behind the scenes to alter that text as you type.  So unfortunately we don't retain any unformatted text.


Actipro Software Support

Posted 12 years ago by Brad Salmon
Avatar

ok, just to confirm, that means that when I set the Text property via code or binding, the value must be formatted with the mask already, correct? It isn't possible to set the Text property to the "raw" data and have it display on the UI formatted.

Any future plans to change this?  Telerik, for example, have Text and MaskedText properties.

- Brad

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

Hi Brad,

Yes that is correct.  I'm not sure you can really store things separately though.  Consider a scenario where you have a mask of "\d.\d".  So basically a digit then dot then digit.  If the user types in "1" then "2", we coerce that via our regex engine to be "1.2".  A Text property (as you described) in that case would return "12" but the real intended value from a MaskedText property is "1.2", which as you can see is a completely different value.  I'm not sure that returning the "12" in that scenario would be very useful since it's effectively a wrong value.


Actipro Software Support

Posted 12 years ago by Brad Salmon
Avatar

I think we just have a different view/opinion of what a Masked field is.  For us, the mask is only to aid in the visual representation or data capture and is not the value.  For example, a Social Security number is truly a number (999228888) but is usually presented with dashes (999-22-8888).  I would store an SSN in the database using a numeric column and therefore it won't be stored with the dashes.  When I retrieve the SSN from the DB and go to display it on the UI I don't want to have to write the code to format it since that is just duplicating what the masked control does.  If I have to write code to add/remove the mask before I save/retrieve data from the DB then the masked control isn't very useful to me.

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

Hi Brad,

I did some experimentation with our code to see if we could reconstruct the typed in data.  Let's take a phone number scenario as an example.  The dash auto inserts after you type three numbers.  If you type all numbers, I can successfully get the "9992228888" value.  However now if we start over and type three numbers and then type a dash, that dash is flagged as an input character.  So I can continue typing numbers only and get "999-2228888".  While the dash is a character that is part of the mask, it can be auto-inserted or typed.  In the case of typed, it flagged as a typed character.  This is a simple scenario and you can see how there could be misleading results because of it.  So I'm not sure the best way to approach improving this for you.


Actipro Software Support

Posted 12 years ago by Brad Salmon
Avatar

I suspect part of the challenge is due to the RegEx engine you use and the power of it.  Some of the other vendor mask controls have the mask defined using special characters.  For example, a "#" might mean "require a digit in this position" so that a phone mask is "(###) ###-####".  That makes it relatively easy to strip the mask off and provide the raw data and vice-versa.  In your example, I don't know why it matters if the dash is typed or auto-inserted.  Ultimately I just want to get the value with all mask characters removed, and conversly want to provide a value with no mask characters and have it display with the mask characters added.

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

That makes sense.  I think the other vendor controls aren't as advanced because with our regex engine we can support multiple paths and have various characters auto fill in based on that, etc.  But on the flip side it's harder to track the difference between what is and isn't a mask character.

For instance we can define patterns like: \d?\d ((AM)|(PM))

If you type "2A", it will fill in "2AM", even though your input was just "2A".  So in cases like that is "A" considered input or mask?


Actipro Software Support

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

Add Comment

Please log in to a validated account to post comments.