问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

电子邮件的正则表达式

发布网友 发布时间:2022-04-23 05:03

我来回答

4个回答

热心网友 时间:2022-05-21 17:37

要求挺多,还没分, 所以,自己改下面的东西去;绝对是你想要的:

######### PERL#################################
# Some things for avoiding backslashitis later on.
$esc = '\\\\'; $Period = '\.';
$space = '\040'; $tab = '\t';
$OpenBR = '\['; $CloseBR = '\]';
$OpenParen = '\('; $CloseParen = '\)';
$NonASCII = '\x80-\xff'; $ctrl = '\000-\037';
$CRlist = '\n\015'; # note: this should really be only \015.

# Items 19, 20, 21
$qtext = qq/[^$esc$NonASCII$CRlist\"]/; # for within "..."
$dtext = qq/[^$esc$NonASCII$CRlist$OpenBR$CloseBR]/; # for within [...]
$quoted_pair = qq< $esc [^$NonASCII] >; # an escaped character

########################################################################
# Items 22 and 23, comment.
# Impossible to do properly with a regex, I make do by allowing at most one level of nesting.
$ctext = qq< [^$esc$NonASCII$CRlist()] >;

# $Cnested matches one non-nested comment.
# It is unrolled, with normal of $ctext, special of $quoted_pair.
$Cnested = qq<
$OpenParen # (
$ctext* # normal*
(?: $quoted_pair $ctext* )* # (special normal*)*
$CloseParen # )
>;

# $comment allows one level of nested parentheses
# It is unrolled, with normal of $ctext, special of ($quoted_pair|$Cnested)
$comment = qq<
$OpenParen # (
$ctext* # normal*
(?: # (
(?: $quoted_pair | $Cnested ) # special
$ctext* # normal*
)* # )*
$CloseParen # )
>;

######################################################################

# $X is optional whitespace/comments.
$X = qq<
[$space$tab]* # Nab whitespace.
(?: $comment [$space$tab]* )* # If comment found, allow more spaces.
>;

# Item 10: atom
$atom_char = qq/[^($space)<>\@,;:\".$esc$OpenBR$CloseBR$ctrl$NonASCII]/;
$atom = qq<
$atom_char+ # some number of atom characters...
(?!$atom_char) # ..not followed by something that could be part of an atom
>;

# Item 11: doublequoted string, unrolled.
$quoted_str = qq<
\" # "
$qtext * # normal
(?: $quoted_pair $qtext * )* # ( special normal* )*
\" # "
>;

# Item 7: word is an atom or quoted string
$word = qq<
(?:
$atom # Atom
| # or
$quoted_str # Quoted string
)
>;

# Item 12: domain-ref is just an atom
$domain_ref = $atom;

# Item 13: domain-literal is like a quoted string, but [...] instead of "..."
$domain_lit = qq<
$OpenBR # [
(?: $dtext | $quoted_pair )* # stuff
$CloseBR # ]
>;

# Item 9: sub-domain is a domain-ref or domain-literal
$sub_domain = qq<
(?:
$domain_ref
|
$domain_lit
)
$X # optional trailing comments
>;

# Item 6: domain is a list of subdomains separated by dots.
$domain = qq<
$sub_domain
(?:
$Period $X $sub_domain
)*
>;

# Item 8: a route. A bunch of "@ $domain" separated by commas, followed by a colon.
$route = qq<
\@ $X $domain
(?: , $X \@ $X $domain )* # additional domains
:
$X # optional trailing comments
>;

# Item 6: local-part is a bunch of $word separated by periods
$local_part = qq<
$word $X
(?:
$Period $X $word $X # additional words
)*
>;

# Item 2: addr-spec is local@domain
$addr_spec = qq<
$local_part \@ $X $domain
>;

# Item 4: route-addr is <route? addr-spec>
$route_addr = qq[
< $X # <
(?: $route )? # optional route
$addr_spec # address spec
> # >
];

# Item 3: phrase........
$phrase_ctrl = '\000-\010\012-\037'; # like ctrl, but without tab

# Like atom-char, but without listing space, and uses phrase_ctrl.
# Since the class is negated, this matches the same as atom-char plus space and tab
$phrase_char =
qq/[^()<>\@,;:\".$esc$OpenBR$CloseBR$NonASCII$phrase_ctrl]/;

# We've worked it so that $word, $comment, and $quoted_str to not consume trailing $X
# because we take care of it manually.
$phrase = qq<
$word # leading word
$phrase_char * # "normal" atoms and/or spaces
(?:
(?: $comment | $quoted_str ) # "special" comment or quoted string
$phrase_char * # more "normal"
)*
>;

## Item #1: mailbox is an addr_spec or a phrase/route_addr
$mailbox = qq<
$X # optional leading comment
(?:
$addr_spec # address
| # or
$phrase $route_addr # name and address
)
>;

#########################################################################
# Here's a little snippet to test it.
# Addresses given on the commandline are described.
#

my $error = 0;
my $valid;
foreach $address (@ARGV) {
$valid = $address =~ m/^$mailbox$/xo;
printf "`$address' is syntactically %s.\n", $valid ? "valid" : "invalid";
$error = 1 if not $valid;
}
exit $error;

热心网友 时间:2022-05-21 18:55

^\w+[-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$

热心网友 时间:2022-05-21 20:30

  正则表达式,又称正规表示法、常规表示法(英语:Regular Expression,在代码中常简写为regex、regexp或RE),计算机科学的一个概念。正则表达式使用单个字符串来描述、匹配一系列符合某个句法规则的字符串。在很多文本编辑器里,正则表达式通常被用来检索、替换那些符合某个模式的文本。
许多程序设计语言都支持利用正则表达式进行字符串操作。例如,在Perl中就内建了一个功能强大的正则表达式引擎。正则表达式这个概念最初是由Unix中的工具软件(例如sed和grep)普及开的。正则表达式通常缩写成“regex”,单数有regexp、regex,复数有regexps、regexes、regexen。
 例如JS:
  email: {
  msg: "邮件地址不合法",
  test: function(obj) {
  return !obj.value || /^[a-zA-Z0-9_+.-]+\@([a-zA-Z0-9-]+\.)+[a-zA-Z0-9]{2,4}$/.test(obj.value);
  }
  }

热心网友 时间:2022-05-21 22:21

\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

这样一般就可以判断了,呵呵

邮箱正确的话还有错误信息,就是因为你上次判断邮箱有误给的提示信息这次没有去掉,简单一点你刷新以下页面或者是跳转一下页面(从本页跳到本页)就可以啦。呵呵
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
...人的五感(视觉、听觉、嗅觉、味觉、触觉)是怎么接收外界刺激,并转... 2024法考中法学类专业指什么 14岁女孩发育有点快啊怎么办? 14岁1米58已经开始发育了,算不算正常,还长高吗 怎样能瘦大腿同时又不长小腿 吃完冰淇淋牙疼是怎么回事 原神4星角色排名-原神4星角色推荐 如何介绍动人的秋色? 在你的家乡,秋天最动人的景色是什么呢? 别人让猪咬了怎么安慰 结缔组织指什么?是如何分布的? 秋冬黄痰黄鼻涕吃什么好 上升星座代表什么,上升星座是什么意思? 邮编的正则表达式 个体工商户怎么给员工交五险一金 个体工商户需要给职工缴纳五险一金吗? 鼻涕是黄色的,比较粘稠,应该吃什么药好 结缔组织功能包括什么 我是个体工商户,想帮员工缴社保,个体工商户缴的社保也是5险1金的吗_百度问一问 上火头疼,嗓子疼,流稠黄鼻涕吃什么药效果好 结缔组织到底是什么? 感冒后鼻子鼻涕黄青浓稠吃什么药 什么是结缔组织 结缔组织有什么作用 鼻涕黄稠吃什么药? 什么是结缔组织 黄色痰黄色鼻涕吃什么药 结缔组织的特点和功能是什么? 热感冒,黄痰,黄黏鼻涕,吃什么药更有效 结缔组织是什么 鼻塞,鼻涕很浓带黄色的,吃什么药物好点 星座的上升星座是什么意思,它和本来的星座的关系是什么? 黄痰浓鼻涕吃什么粥 结缔组织的作用 java正则表达式提取邮件地址 结缔组织分布在哪里 收件人正则表达式 结缔组织的分类有哪些 求一个正则表达式用来判断Email是否符合规范。要求 以字母开头, 中间... 我们通常说的结缔组织是指什么? 上升星座代表什么,上升星座是什么意思 Email 正则表达式求助 需满足以下条件 结缔组织的特点和功能 什么是上升星座?有什么用处? 结缔组织有什么? c#中如何利用正则表达式判定邮箱的合法性 上升星座什么意思? 什么是上升星座? 利用正则表达式:找到一段字符串中所有的IP地址和Email地址 人体结缔组织有哪些 上升星座是什么意思和星座的区别?