C# custom mask for textbox

uniquepito picture uniquepito · Aug 20, 2011 · Viewed 7.8k times · Source

I know there is masked textbox component for C#, but what I need is to create masked text box which requires entered text in format: LLL/LLL but when I enter such mask into Mask property in preview and mask I see separator "." but not "/" as I want to have. Any help? Thanks

Answer

Hans Passant picture Hans Passant · Aug 20, 2011

The / character is the date separator character in the mask. What you'll actually get depends on your culture preferences. To get a literal / you'll have to escape it with a \. Like this:

        this.maskedTextBox1.Mask = @"LLL\/LLL";

Don't use the @ when you use the Properties window.