角互联网可路由的电子邮件地址验证 [英] Angular Internet Routable Email Address Validation

查看:231
本文介绍了角互联网可路由的电子邮件地址验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格,我需要提交前验证互联网路由的电子邮件地址并拒绝本地路由。无论 NG-模式=email.text NG-模式=电子邮件通过鲍勃@鲍勃这应该会失败,因为这些是本地网络以外的客户的电子邮件地址。

下面的不要给我什么我正在寻找(很多正在使用简陋RegExs不完全符合RFC标准或不否认本地路由):

HTTP://www.regular-ex$p$pssions.info /email.html 该引用 RFC 5322 与常规的前pression:

  \\ A(?:[!?A-0-9#$%&放大器;'* + / = ^ _`{|}〜 - ] +(:\\? [A-Z0-9#$%&放大器;!?* + / = ^ _`{|}〜 - ] +)*
  | (?:[\\ x01- \\ X08 \\ X0B \\ X0C \\ x0e- \\ X1F \\ X21 \\ x23- \\ x5b \\ x5d- \\ 0x7F部分]
      | \\\\ [\\ x01- \\ X09 \\ X0B \\ X0C \\ x0e- \\ 0x7F部分)*)
@(([A-Z0-9]([A-Z0-9 - ] * [A-Z0-9])\\)+ [A-Z0-9](:?????[ A-Z0-9 - ] * [A-Z0-9])?
  | \\ [(:( ?: 25 [0-5] | 2 [0-4] [0-9] |?[01] [0-9] [0-9])。\\){3}
       ??(:25 [0-5] | 2 [0-4] [0-9] | [01] [0-9] [0-9] | [一个-Z0-9 - ] * [A- 0-9]:
          (?:[\\ x01- \\ X08 \\ X0B \\ X0C \\ x0e- \\ X1F \\ x21- \\ X5A \\ x53- \\ 0x7F部分]
          | \\\\ [\\ x01- \\ X09 \\ X0B \\ X0C \\ x0e- \\ 0x7F部分)+)
     \\])\\ Z

有没有一种方法,使上述成一个正则表达式,需要一个 TLD型,所以它是互联网路由?具体来说,在那里我可以用它在 NG-模式,如 NG-模式=<正则表达式放在这里>中的形式?


解决方案

我喜欢这一个从这里结果
http://www.w3.org/TR/html5 /forms.html#valid-e-mail-address

<$p$p><$c$c>/^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/

扩展

  ^
 [A-ZA-Z0-9#$%&安培;!?* + / = ^ _`{|}〜 - ] +
 @
 [A-ZA-Z0-9]
 (?:
      [A-ZA-Z0-9 - ] {0,61}
      [A-ZA-Z0-9]
 )?
 (?:
      \\。
      [A-ZA-Z0-9]
      (?:
           [A-ZA-Z0-9 - ] {0,61}
           [A-ZA-Z0-9]
      )?
 )*
 $

I have a form which I need to verify internet routable email addresses before submission and deny local routing. Both ng-pattern="email.text" and ng-pattern="email"pass bob@bob which should fail, as these are customer email addresses outside of the local network.

The following do not give me what I'm looking for (many are using rudimentary RegExs that don't fully conform to RFC standards or don't deny local routing):

Reading http://www.regular-expressions.info/email.html it references RFC 5322 with regular expression:

\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*
  |  "(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]
      |  \\[\x01-\x09\x0b\x0c\x0e-\x7f])*")
@ (?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?
  |  \[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}
       (?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:
          (?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]
          |  \\[\x01-\x09\x0b\x0c\x0e-\x7f])+)
     \])\z

Is there a way to make the above into a RegEx that requires a tld-type, so it is internet routable? Specifically, where I can use it in a ng-pattern, like ng-pattern="<regex goes here>" in the form?

解决方案

I like this one from here
http://www.w3.org/TR/html5/forms.html#valid-e-mail-address

/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/  

Expanded

 ^ 
 [a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+ 
 @
 [a-zA-Z0-9] 
 (?:
      [a-zA-Z0-9-]{0,61} 
      [a-zA-Z0-9] 
 )?
 (?:
      \. 
      [a-zA-Z0-9] 
      (?:
           [a-zA-Z0-9-]{0,61} 
           [a-zA-Z0-9] 
      )?
 )*
 $ 

这篇关于角互联网可路由的电子邮件地址验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆