具有一个域的电子邮件的正则表达式 [英] regular expression for email with one domain

查看:60
本文介绍了具有一个域的电子邮件的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在javascript中最终确定正则表达式

允许具有某个域的电子邮件有效。


这是我所拥有的到目前为止:


var emailFilter2 = / [^ \w\-\。] \ @aol.com/;

if(! (emailFilter2.test(strng))){

error ="请输入AOL域名的有效电子邮件地址。\\ n

\ n" ;; < br $>
}

感谢您对此的任何帮助。

路易斯

I am trying to finalize a regular expression in javascript to only
allow emails with a certain domain to be valid.

Here is what I have so far:

var emailFilter2=/[^\w\-\.]\@aol.com/;
if(!(emailFilter2.test(strng))) {
error = "Please enter a valid email address with the AOL domain.\n
\n";
}
Thanks for any help with this.
Louis

推荐答案

ll写道:



ll wrote:

Hi,

我想在javascript中完成正则表达式只有

允许某个域的电子邮件有效。
I am trying to finalize a regular expression in javascript to only
allow emails with a certain domain to be valid.



不幸的是,考虑到相关RFC中提供的语法选项,电子邮件地址不能(可能)使用一个

单一正则表达式进行测试。 br />
此外,一个有效的地址,即尊重

规范中定义的格式,可能根本就没有收到邮件(可能是一些假的

地址)。


请查看以下页面,附录,第5部分,验证电子邮件

地址,作者:Elijah Pogonatus。另外,请注意作者提供的两个例子




< URL:http://www.faqs.org/faqs/mail /寻址/>


问题是,重新考虑你的方法可能更好。如果您只接受AOL电子邮件地址,那么为什么不使用类似的东西(沿着

并将一些确认链接发送到该地址):


---

请输入您的电子邮件地址(仅限AOL)。

< input type =" text" name =" email"> @ aol.com

---


亲切问候。

Unfortunately, email addresses cannot (probably) be tested with one
single regexp, given the syntax options available in the relevant RFC.
Moreover, a valid address, i.e. respecting the format defined in the
specification, may simply not be receiving mail (it could be some fake
address).

Please check the following page, Appendix, Part 5, "Verifying Email
Addresses", by Elijah Pogonatus. Also, pay attention to the two examples
provided by the author.

<URL:http://www.faqs.org/faqs/mail/addressing/>

The thing is, it might simply be better to rethink your approach. If you
accept only AOL email addresses, then why not use something like (along
with some confirmation link sent to the address):

---
Please enter your email address (AOL only).
<input type="text" name="email">@aol.com
---

Kind regards.


ll于2007年2月13日在comp.lang.javascript中写道
ll wrote on 13 feb 2007 in comp.lang.javascript:

我正在尝试在javascript中最终确定正则表达式只有

允许某个域名的电子邮件有效。


这是我到目前为止:


var emailFilter2 = / [^ \w\-\。] \ @aol.com/;
I am trying to finalize a regular expression in javascript to only
allow emails with a certain domain to be valid.

Here is what I have so far:

var emailFilter2=/[^\w\-\.]\@aol.com/;



。应该转义aol之后。

你应该允许不区分大小写。

你应该用

The . after aol should be escaped.
You should allow for case insensitivity.
You should test for the end of string with


来测试字符串的结尾。
.

if(!(emailFilter2.test(strng))){

error ="请输入AOL的有效电子邮件地址

domain.\ n

\ n" ;;

}
if(!(emailFilter2.test(strng))) {
error = "Please enter a valid email address with the AOL
domain.\n
\n";
}



更简单,如果您只对测试域名部分感兴趣:


if(/.@ aol\.com


Far simpler, if you are only interested in testing the domain part:

if (/.@aol\.com


这篇关于具有一个域的电子邮件的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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