FixedMaskedTextProvider
ReferencesImplements a fixed masked text provider, using the standard System.ComponentModel.MaskedTextProvider.
Remarks: This wraps the standard provider in an interface used by the MaskedTextBox so that we can provide different implementations of masked text providers. The implementation of this is defined in each platform assembly so that we can use this from a PCL assembly.
Constructors
FixedMaskedTextProvider
#public FixedMaskedTextProvider(string mask, CultureInfo culture = null, bool allowPromptAsInput = true, bool restrictToAscii = false)
Initializes a new instance of the FixedMaskedTextProvider class.
Parameters:
| mask (string) | Mask for the input. See Mask for mask format. |
| culture (CultureInfo = null) | Culture to format date/time separators and numeric placeholders. |
| allowPromptAsInput (bool = true) | If set to true, then allow the PromptChar as valid input. |
| restrictToAscii (bool = false) | If set to true, restrict input characters to ASCII only (a-z or A-Z). |
Properties
AllowPromptAsInput
#Gets a value indicating whether the PromptChar can be a valid input character by the user.
Value:
true to allow prompt as input; otherwise, false.AsciiOnly
#Gets a value indicating whether the input only accepts ascii characters A-Z or a-z.
Value:
true if only ASCII characters are accepted; otherwise, false.AutoAdvance
#Gets or sets a value indicating that the cursor position will advance past literals to the next available edit position automatically.
Value:
true to auto advance past literals; otherwise, false.EditPositions
#Gets an enumeration of all valid edit positions in the mask.
Value: The valid edit positions.
Implements: EditPositions
IncludeLiterals
#Gets or sets a value indicating that the Text property includes literals in the mask.
Value:
true to include literals; otherwise, false.IncludePrompt
#Gets or sets a value indicating that the Text property includes prompt characters for each edit position in the mask.
Value:
true to include prompt; otherwise, false.IsPassword
#Gets or sets a value indicating whether the mask should be password protected.
Value:
true if this instance is password; otherwise, false.Mask
#Gets the mask for this provider, as specified in the constructor.
Remarks: The mask format can consist of the following characters: 0 - Required digit from 0-9. 9 - Optional digit or space. # - Optional digit, space, or sign (+/-). If blank, then it is output as a space in the Text value. L - Required upper or lowercase letter. ? - Optional upper or lowercase letter. & - Required character. If AsciiOnly is true, then behaves like L. C - Optional character. If AsciiOnly is true, then behaves like ?. A - Required alphanumeric character. If AsciiOnly is true, then behaves like L. a - Optional alphanumeric. If AsciiOnly is true, then behaves like ?. . - Decimal placeholder based on the specified Culture for the mask. , - Thousands placeholder based on the specified Culture for the mask. : - Time separator based on the specified Culture for the mask. / - Date separator based on the specified Culture for the mask. $ - Currency symbol based on the specified Culture for the mask. < - Shift all characters that follow to lower case. > - Shift all characters that follow to upper case. | - Disables a previous shift to upper or lower case. \ - Escape the following character into a literal. All other characters are treated as literal and cannot be moved or deleted.
Value: The text mask.
MaskCompleted
#Gets a value indicating whether the mask has all required text to pass its validation.
MaskFull
#Gets a value indicating that all available edit positions in the mask have been filled out.
Value:
true if mask the mask is full; otherwise, false.PasswordChar
#In password mode, gets or sets the character to show for filled edit characters in the mask.
SkipLiterals
#Gets or sets a value indicating that the user can type literals to skip them in the mask.
Value:
true to allow the user to enter literals to skip them; otherwise, false.Methods
Clear
#Called to clear a range of characters at the specified position in the masked text.
Remarks: The cleared characters usually show the prompt character after cleared. This is useful for fixed length mask providers. For variable length, this is usually the same as calling Delete(int, int, bool).
Parameters:
| position (ref int) | Position to clear at. |
| length (int) | Length of text (in the mask) to clear |
| forward (bool) | true to delete the text forward, or false to delete backward |
Returns:
true when the deletion was successful, or false if it failed.Implements: Clear
public virtual void CommitText()
Called to update the display text after changes to the mask value.
Remarks: This is called after user changes to the mask value is complete, such as when the control loses focus, or when the user presses enter. This allows the mask provider to update the display text after changes are made to the value, while still allowing the user to type in the text without it changing until they are done.
Implements: CommitText
Delete
#Called to delete a range of characters at the specified position in the masked text.
Insert
#Called to insert a character at the specified position in the masked text.
Returns:
true when the insertion was successful, or false if it failed.Implements: Insert
Replaces every whitespace character in
text that isn't a regular space with one.Remarks: A mask can only use the regular space (U+0020) as whitespace. Any other whitespace character - such as the narrow no-break space that ICU-based cultures use in front of the AM/PM designator - is rejected as an invalid mask character, and cannot be escaped as a literal either, so it has to be substituted instead. Text that is going to be set on a mask has to be normalized the same way, otherwise it no longer lines up with the literals of the mask it was formatted for. See DateTimeMaskedTextProvider, which normalizes the date/time format it builds from the culture for that reason.
Parameters:
| text (string) | Mask or text to normalize the whitespace of. |
Returns: The text with all of its whitespace characters turned into regular spaces.