Textbox numbers values
-
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
-
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
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("## - ## - ##") -
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
Alternatively, if you want to show the user the fomatted text, the
MaskedTextBox
control withMask
property set as below may be usedMaskTextBox1.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[^]