Control MaskedTextBox
Control MaskedTextBox
Control MaskedTextBox
El control MaskedTextBox es un control que le permite entrada y
salida de datos al igual que el TextBox, su diferencia es que en el control MaskedTextBox se
pueden establecer “Máscaras” a través de su atributo Mask, las máscaras son formatos que
limitan el número y tipo de caracteres que se pueden ingresar al MaskedTextBox. Esto permite
controlar mejor los datos que el usuario puede ingresar.
Masking Description
element
0 Digit, required. This element will accept any single digit between 0 and 9.
9 Digit or space, optional.
# Digit or space, optional. If this position is blank in the mask, it will be rendered as a space in
the Text property. Plus (+) and minus (-) signs are allowed.
L Letter, required. Restricts input to the ASCII letters a-z and A-Z. This mask element is equivalent to
[a-zA-Z] in regular expressions.
? Letter, optional. Restricts input to the ASCII letters a-z and A-Z. This mask element is equivalent to
[a-zA-Z]? in regular expressions.
& Character, required. If the AsciiOnly property is set to true, this element behaves like the "L" element.
Masking Description
element
C Character, optional. Any non-control character. If the AsciiOnly property is set to true, this element behaves like
the "?" element.
A Alphanumeric, required. If the AsciiOnly property is set to true, the only characters it will accept are the ASCII
letters a-z and A-Z. This mask element behaves like the "a" element.
a Alphanumeric, optional. If the AsciiOnly property is set to true, the only characters it will accept are the ASCII
letters a-z and A-Z. This mask element behaves like the "A" element.
. Decimal placeholder. The actual display character used will be the decimal symbol appropriate to the format
provider, as determined by the control's FormatProvider property.
, Thousands placeholder. The actual display character used will be the thousands placeholder appropriate to the
format provider, as determined by the control's FormatProvider property.
: Time separator. The actual display character used will be the time symbol appropriate to the format provider, as
determined by the control's FormatProvider property.
/ Date separator. The actual display character used will be the date symbol appropriate to the format provider, as
determined by the control's FormatProvider property.
$ Currency symbol. The actual character displayed will be the currency symbol appropriate to the format provider, as
determined by the control's FormatProvider property.
< Shift down. Converts all characters that follow to lowercase.
> Shift up. Converts all characters that follow to uppercase.
| Disable a previous shift up or shift down.
\ Escape. Escapes a mask character, turning it into a literal. "\\" is the escape sequence for a backslash.
All other Literals. All non-mask elements will appear as themselves within MaskedTextBox. Literals always occupy a static
characters position in the mask at run time, and cannot be moved or deleted by the user.
Fuente: https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.maskedtextbox.mask?view=netcore-3.1#System_Windows_Forms_MaskedTextBox_Mask
1
MSc. Luis Ernesto Benavides Sellan – Control MaskedTextBox
Ejemplos:
Mask 0000000000
Mask 00/00/0000
Para un código de producto que tenga tres letras obligatorias, un guión y dos dígitos
Mask LLL-00
Para un número de teléfono de 9 dígitos, con los tres primeros opcionales, un guión y
los restantes obligatorios.
Mask 999-000000
Caso Práctico
Para un código catastral del Municipio de Guayaquil, el cual consta de 15 dígitos, con
grupos heterogéneos separados en guiones.