How to get raw text from MaskedTextBox?

佐手、 提交于 2019-12-31 01:53:54

问题


I have a MaskedTextBox with this mask (999) 999 9999. When user inputs a number the text property would give this to me :

(0881) 444 5445

But I want to save the raw text to database field like this: 08814445445. How can I do that?


回答1:


Based on what I found here you can set the TextMaskFormat-Property to MaskFormat.ExcludePromptAndLiterals. That should be you solution.

The MaskFormat-Enumeration holds some "options" for the MaskedTextBox.
They are:

  1. ExcludePromptAndLiterals Return only text input by the user.
  2. IncludeLiterals Return text input by the user as well as any literal characters defined in the mask.
  3. IncludePrompt Return text input by the user as well as any instances of the prompt character.
  4. IncludePromptAndLiterals Return text input by the user as well as any literal characters defined in the mask and any instances of the prompt character.

The default is IncludeLiterals




回答2:


Try setting the maskedTextBox.TextMaskFormat property to MaskFormat.ExcludePromptAndLiterals



来源:https://stackoverflow.com/questions/34151696/how-to-get-raw-text-from-maskedtextbox

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!