Results 1 to 4 of 4

Thread: [RESOLVED] How do i get the VALUE of a MaskedTextBox?

  1. #1

    Thread Starter
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Resolved [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)
    .
    ~Peter


  2. #2
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,335

    Re: How do i get the VALUE of a MaskedTextBox?

    MaskedTextBox1.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    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:
    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Thumbs up 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
    .
    ~Peter


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width