Format for TextBox

Posted on 2012-08-16
Last Modified: 2012-08-16
I have a Windows.Forms.TextBox in which the user types data, and the data must be in a very particular format. The length is 10 characters and the format is "abc0000000", where "abc" is exactly "abc"  (ie not just any alpha) and 0 represents any digit 0-9. What is the best way to enforce this?
Question by:allelopath
    LVL 22

    Assisted Solution

    probably be best to use a regex expression as a mask


    or something like that -- there are a lot of regex libraries online.
    LVL 13

    Accepted Solution

    You could use a MaskedTextBox with this mask: \abc0000000

    Or you could just put the mask to 0000000 and put a label on the left part of the Masked Text Box with "abc" in it...

    Regular expressions is another way to go, but your validation looks simple enough to do it with that control.

    Hope it helps.
    LVL 1

    Author Comment

    It may be important to say that this TextBox can also be populated by previously existing records from a database, which are in the correct format.
    LVL 1

    Author Comment

    I've tried the mask  \abc0000000, and that works, but I didn't specify the mask correctly in the original post, its actually ABC not abc, so I would need \ABC0000000, but this line:
    this.myMaskedTextBox.Mask = "\ABC0000000";
    doesn't compile.

    According the documentation, A is a masking element.
    LVL 1

    Author Comment

    Oh, has to be \\ABC0000000

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
    In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now