Localizing MaskedTextBox Masks

The System.Windows.Forms.MaskedTextBox class has a property called Mask that represents the input mask for the text box. This mask is clearly specific to a culture. This entry discusses this property, its associated property editor and the localized masks provider by this property editor.

Click on the MaskedTextBox.Mask property in the Properties Window in Visual Studio and then click on the ellipses in the property and you will most likely see the following Input Mask dialog:-


The dialog represents a collection of example masks for the CurrentCulture ("English (United States)" in this example). The dialog itself is dependant upon the current culture and therefore it is determined by the setting in the Regional and Language Options dialog. You can, for example, see the Spanish examples by closing Visual Studio, setting the culture to Spanish (Spain), restarting Visual Studio and opening the dialog again:-


The number of examples is specific to the culture so if you open the dialog for German (Germany) you will see just 4 entries:-

Unfortunately this list is hard coded and there is no way to extend or customize the list. The examples are hard coded in the internal MaskDescriptorTemplate class. The possible values are shown here:-

en-US DescriptionsEnglish / InvariantArabicGermanFrenchItalianSpanishJapaneseChinese SimplifiedChinese TraditionalKorean
Numeric (5-digits)00000n/an/a9999999999999999999999999n/a99999
Phone Number(999)000-0000(999)000-0000n/a00 00 00 00 00 000000 00000(999)000-000099900-9990-0000(900)9000-0000(00)9000-0000(999)9000-0000
Phone Number no Area Code000-0000000-0000n/an/an/an/an/a9000-0000n/a9000-0000
Short Date00 /00 /000000 /00 /000000/00/000000/00/000000/00/000000/00/00000000/00/000000-00-000000/00/000000-00-00
Short date and time (US)00 /00 /0000 00:0000 /00 /0000 00:0000/00/0000 00:0000/00/0000 00:0000/00/0000 00:0000/00/0000 00:000000/00/00 00:00:000000-00-00 90:00:000000/00/00 00:00:000000-00-00 90:00
Social Security Number000-00-0000000-00-0000n/a0 00 00 00 000 000 00n/a000-00-0000n/an/an/a000000-0000000
Time (US)90:0090:0090:0000:0000:0000:0090:0090:0090:0090:00
Time (European/Military)00:0000:00n/an/an/an/an/an/an/an/a
Zip Code00000-9999n/a00000000000000000000000-000000000099000000-000

Italian, Spanish, Japanese, Chinese (Simplified and Traditional) and Korean have additional formats for cell phone numbers. Japanese has additional date/time formats for the Japanese calendar. Chinese (Simplified and Traditional) has additional date/time formats and identity card formats. Korean has additional date/time formats.

The English formats are used for Engl

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Guy Smith-Ferrier
Posted on: Wednesday, November 15, 2006 at 11:09 PM
Categories: Internationalization
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

Related posts

Comments