Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Textbox numbers values

Textbox numbers values

Scheduled Pinned Locked Moved Visual Basic
helptutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Venecos
    wrote on last edited by
    #1

    Hi everyone, I have a textbox which holds numbers like e.g., xxxxxx I wonder how to change that value entered by the user to xx-xx-xx. I'm trying several regular expressions like: OpNumbers.Replace(OpNumbers, "^(\d{6}|(\d{2}-\d{2}-\{2}))$") and also : Format(lblOPReferenceNumber.Text.Trim, "## - ## - ##"). I'm not getting the output that need it. I'm pretty sure that I might be doing something wrong at some point. Thank you for you help. Venecos

    B P 2 Replies Last reply
    0
    • V Venecos

      Hi everyone, I have a textbox which holds numbers like e.g., xxxxxx I wonder how to change that value entered by the user to xx-xx-xx. I'm trying several regular expressions like: OpNumbers.Replace(OpNumbers, "^(\d{6}|(\d{2}-\d{2}-\{2}))$") and also : Format(lblOPReferenceNumber.Text.Trim, "## - ## - ##"). I'm not getting the output that need it. I'm pretty sure that I might be doing something wrong at some point. Thank you for you help. Venecos

      B Offline
      B Offline
      Bernhard Hiller
      wrote on last edited by
      #2

      Do you need leading zeros? Then you must use "0" instead of "#".

      Dim number as int = int.Parse(textbox1.Text)
      Dim result as string = number.ToString("00 - 00 - 00")
      'without leading zeros:
      Dim result2 as string = number.ToString("## - ## - ##")

      1 Reply Last reply
      0
      • V Venecos

        Hi everyone, I have a textbox which holds numbers like e.g., xxxxxx I wonder how to change that value entered by the user to xx-xx-xx. I'm trying several regular expressions like: OpNumbers.Replace(OpNumbers, "^(\d{6}|(\d{2}-\d{2}-\{2}))$") and also : Format(lblOPReferenceNumber.Text.Trim, "## - ## - ##"). I'm not getting the output that need it. I'm pretty sure that I might be doing something wrong at some point. Thank you for you help. Venecos

        P Offline
        P Offline
        ProEnggSoft
        wrote on last edited by
        #3

        Alternatively, if you want to show the user the fomatted text, the MaskedTextBox control with Mask property set as below may be used

        MaskTextBox1.Mask = "00 - 00 - 00"
        maskedTextBox1.TextMaskFormat = MaskFormat.IncludePromptAndLiterals
        string maskedText = maskedTextBox1.Text
        'Replace the blank characters
        maskedText = maskedText.Replace("_","0")

        The mask characters are explained here http://msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.mask.aspx[^]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups