views:

512

answers:

2

Is there a way to use MaskedTextBox without displaying the PromptChar? I would like to specify a mask to validate input against, but I don't want any prompt characters to take up space during edit mode.

The reason for this is when I want to accept free text with a limited character set, all characters are optional alphanumerics. The problem I have is that when I select all text, even the prompt characters are selected.

Setting PromptChar to (" ") doesn't work. Setting it to Zero-width space (\u200B) seems to work, but weird things happen when the mask reaches a certain length (13 characters seems to be the magic number). Or would it be best to just roll my own?

A: 

How about just using a textbox and then using a regex (or some other validation process) to verify that the text is valid when the control loses focus. Alternatively, if this is a Window's app, jump on the TextChanging event (or KeyPress) and stop any invalid characters actually getting into the input in the first place.

This can be done in javascript for a web page also.

Lazarus
I went with this in the end. I was hoping to use MaskedTextBox since it has more features and is more flexible. But of course a quick solution works just as well.
Jeremy
A: 

did you check the property CutCopyMaskFormat ?

it seems that it's set to : IncludePrompt or IncludePromptAndLiterals.

najmeddine