[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 409
  • Last Modified:

Format for TextBox

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?
0
allelopath
Asked:
allelopath
  • 3
2 Solutions
 
p_davisCommented:
probably be best to use a regex expression as a mask

abc[0-9][0-9][0-9][0-9][0-9][0-9][0-9]

or something like that -- there are a lot of regex libraries online.
0
 
LIONKINGCommented:
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.
0
 
allelopathAuthor Commented:
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.
0
 
allelopathAuthor Commented:
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.
0
 
allelopathAuthor Commented:
Oh, has to be \\ABC0000000
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now