REGEX email validator

0

The goal of my regex is to validate an mail address that may or may not exist according to the following parameters:

  • does not contain characters other than letters, numbers, underscores, and @
  • only 1 @
  • before @, there must be between 3 and 8 characters
  • after the arroba, there should be a total of 4 to 12 characters, with exactly one point.

The expression I have so far allows me to control that there are between 4 and 12 characters before the period after the arroba, but I can not modify it so that it fulfills the requested requirements.

The expression is:

  

^ (? = [^ @] {3,8} @) ([\ w.-] [a-zA-Z0-9 _] @ (? =. {4,12}. [^ .] $) [\ w -] [a-zA-Z0-9]. [a-zA-Z] [a-zA-Z] [a-zA-Z ]) $

    
asked by Diego Collao Alcayaga 30.11.2018 в 16:57
source

1 answer

0

I usually use this website, regular expression generator , to generate some regular expressions and allows you to choose the programming language for the expression.

  • Just enter the required format
  • After das in "Show Matches"
  • And I will show you the suggestions so that you can go arming the expression.
  • for an example

    the email: [email protected]

    regular expression for javascript:

    <html>
      <body>
        <script language=javascript>
          var txt='[email protected]';
    
          var re1='([\w-+]+(?:\.[\w-+]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7})';    // Email Address 1
    
          var p = new RegExp(re1,["i"]);
          var m = p.exec(txt);
          if (m != null)
          {
              var email1=m[1];
              document.write("("+email1.replace(/</,"&lt;")+")"+"\n");
          }
        </script>
      </body>
    </html>
    

    I hope it serves you.

        
    answered by 30.11.2018 / 19:29
    source