How to make an email mask in a Windows Forms application? I'm using the MaskedTextBox to validate fixed-length fields, for example: zip and CPF the problem is when the mascara is of varying size eg email ?
How to make an email mask in a Windows Forms application? I'm using the MaskedTextBox to validate fixed-length fields, for example: zip and CPF the problem is when the mascara is of varying size eg email ?
You can use the System.Text.RegularExpressions;
namespace to generate a rule and calculate it where you want.
I created a very simple example to exemplify the use of class Regex
, where I run the rule inside a click event, to show the use of the rule. Follow Image below:
Asyoucanseequitesimply,knowingthenamespacebetteryouwillseethatthepossibilitiesarenumerous.
"^(\d{3}.\d{3}.\d{3}-\d{2})|(\d{11})$"
^\d{5}-\d{3}$
"^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$"
Rule used in the example:
Regex regra = new Regex(@"^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$");