8

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?

rebatoma
  • 734
  • 1
  • 17
  • 32

3 Answers3

18

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

Mischa
  • 1,303
  • 12
  • 24
4

It's Work for me

Just Change Property Value

enter image description here

Adnan Zaheer
  • 392
  • 3
  • 13
1

Try setting the maskedTextBox.TextMaskFormat property to MaskFormat.ExcludePromptAndLiterals

Alex
  • 937
  • 3
  • 20
  • 44
  • "Try" without explanation should be comment. – Damian Kozlak Dec 08 '15 at 09:24
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - [From Review](/review/low-quality-posts/10482320) – swidmann Dec 08 '15 at 09:29
  • 1
    @swidmann This does provide an answer to the question. Trivial questions that can be easily answered by reading the [documentation](https://msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.textmaskformat%28v=vs.110%29.aspx) often may have trivially looking answers. – GSerg Dec 08 '15 at 09:34
  • 1
    @GSerg, I agree the text from review does not fit 100%, but I miss some explanation in this answer – swidmann Dec 08 '15 at 09:38