Mask for input field of varied size with windows forms

0

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 ?

    
asked by anonymous 12.02.2018 / 13:50

1 answer

0

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.

  • CPF:"^(\d{3}.\d{3}.\d{3}-\d{2})|(\d{11})$"
  • Zip Code: ^\d{5}-\d{3}$
  • EMAIL: "^[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,})$");
    
12.02.2018 / 20:45