[RESOLVED] How do i get the VALUE of a MaskedTextBox?
How do I get just the value that is typed into a MaskedTextBox?
For instance, if I have a MaskedTextBox with the mask of “(999) 000-0000 x000000”, and the user typed in a phone number, like (905) 555-1234 x6869.
How do I get back the raw number value, without the mask? (ie: 90555512346869)
.
Re: How do i get the VALUE of a MaskedTextBox?
MaskedTextBox1.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals
Re: How do i get the VALUE of a MaskedTextBox?
This is yet another example of a a question that could have been answered easily by reading the documentation. The doco for the MaskedTextBox.Text property says:
Quote:
Strings retrieved using this property are formatted according to the control's formatting properties, such as Mask and TextMaskFormat.
Following the link to the doco for the TextMaskFormat property we find this:
Quote:
The TextMaskFormat property determines how the literal and prompt characters in the mask are processed when the generating the formatted string. More specifically, it determines whether literal characters, prompt characters, or both are included in the Text property.
Re: How do i get the VALUE of a MaskedTextBox?
Thanks for the help. That solves it.
And for anyone that is searching and looking for the solution,...
In your Form Load event:
Code:
With mtbHomePhone
.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals
.HidePromptOnLeave = True
.Mask = "(999) 000-0000 x000000"
End With
Then you can write code in a button like this:
Code:
mtbHomePhone.Text = "90555512346869"
lblResults1.Text = "Length of phone number: " & mtbHomePhone.Text.Length
lblResults2.Text = "phone number value: " & mtbHomePhone.Text
.