Class RegexMask
- Namespace
- MudBlazor
- Assembly
- MudBlazor.dll
An input mask consisting of a regular expression.
public class RegexMask : BaseMask, IMask
- Inheritance
-
RegexMask
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
RegexMask(string, string)
Creates a mask using a regular expression.
public RegexMask(string regex, string mask = null)
Parameters
regex
stringThe regular expression used to validate inputs. Must begin with
^
and end with$
.mask
stringThe structure of the accepted input. When
null
, the regular expression is used for the mask.
Remarks
The regular expression must be able to match partial inputs, must begin with ^
, and must end with \(</code> to work properly (e.g. <code>^[0-9]+\)
).
Consider using BlockMask to generate the regular expression automatically.
Fields
_regex
protected Regex _regex
Field Value
_regexPattern
protected string _regexPattern
Field Value
Properties
Delimiters
The characters which are jumped over when adding an input character.
public string Delimiters { get; protected set; }
Property Value
Remarks
Defaults to null
. For example: for a delimiter of .
, a mask of ^[0-9].[0-9].[0-9]$
, and characters typed of 012
, the resulting text would be 0.1.2
Methods
AlignAgainstMask(string)
Applies an input to the mask.
protected virtual string AlignAgainstMask(string text)
Parameters
text
stringThe text to apply to the mask.
Returns
- string
The text input with any delimiters and placeholders applied.
Backspace()
Triggers a backspace at the current cursor position.
public override void Backspace()
Remarks
Has the same effect as pressing the Backspace
key.
Delete()
Triggers a delete at the current cursor position.
public override void Delete()
Remarks
Has the same effect as pressing the Delete
key.
DeleteSelection(bool)
Deletes the selected characters.
protected override void DeleteSelection(bool align)
Parameters
align
boolWhen
true
, the text to the right of the selection will be shifted to the left.
Email(string)
Gets a mask for email addresses.
public static RegexMask Email(string mask = "Ex. user@domain.com")
Parameters
mask
stringDefaults to
Ex. user@domain.com
. The mask to display.
Returns
IPv4(bool, char)
Gets a mask for IPv4 addresses with optional port masking.
public static RegexMask IPv4(bool includePort = false, char maskChar = '0')
Parameters
includePort
boolDefaults to
false
. Whentrue
, a port number (from0
to65535
) is allowed.maskChar
charDefaults to
0
. The mask character for address digits.
Returns
IPv6(bool, char, char)
Gets a mask for IPv6 addresses with optional port masking.
public static RegexMask IPv6(bool includePort = false, char maskChar = 'X', char portMaskChar = '0')
Parameters
includePort
boolDefaults to
false
. Whentrue
, a port number (from0
to65535
) is allowed.maskChar
charDefaults to
X
. The mask character for address digits.portMaskChar
charDefaults to
0
. The mask character for port digits.
Returns
InitInternals()
Initializes this mask's characters and delimiters.
protected override void InitInternals()
InitRegex()
Initializes the regular expression.
protected virtual void InitRegex()
Insert(string)
Inserts text at the current cursor position.
public override void Insert(string input)
Parameters
input
stringThe characters to insert.
UpdateFrom(IMask)
Copies the mask and mask characters from the specified mask.
public override void UpdateFrom(IMask other)
Parameters
other
IMaskThe mask to copy from.