javascript 请解释此电子邮件验证正则表达式:

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6646613/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 21:23:26  来源:igfitidea点击:

Please explain this e-mail validation regular expression:

javascript

提问by user737618

I have this script uses regular expressions to check that a form field contains a valid email address.Please explain me from declare

我有这个脚本使用正则表达式来检查表单字段是否包含有效的电子邮件地址。请从声明中解释我

var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;

Thank you

谢谢

Source:

来源:

<script type="text/javascript">

/***********************************************
* Email Validation script- ? Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i

function checkmail(e){
var returnval=emailfilter.test(e.value)
if (returnval==false){
alert("Please enter a valid email address.")
e.select()
}
return returnval
}

</script>

<form>
<input name="myemail" type="text" style="width: 270px"> <input type="submit" onClick="return checkmail(this.form.myemail)" value="Submit" />

</form>

回答by rockerest

/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i

/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i

/= Begin an expression
^= The matched string must begin here, and only begin here
\w= any word (letters, digits, underscores)
+= match previous expression at least once, unlimited number of times
[]= match any character inside the brackets, but only match one
\+\.= match a literal +or .
\w= another word
-= match a literal -
*= match the previous expression zero or infinite times
@= match a literal @symbol
()= make everything inside the parentheses a group (and make them referencable)
[]= another character set
\w-= match any word or a literal -
+= another 1 to infinityquantifier
\.= match another literal .
*= another 0 to infinityquantifier
\w+= match a word at least once
[\w-]*\.= match a word or a dash at least zero times, followed by a literal .
()= another group
[a-z]{2,4}= match lowercase letters at least 2 times but no more than 4 times
|= "or" (does not match pipe)
\d+= match at least 1 digit
$= the end of the string
/= end an expression
i= test the string in a case insensitive manner

/= 开始一个表达式
^= 匹配的字符串必须从这里开始,并且只从这里开始
\w= 任何单词(字母、数字、下划线)
+= 匹配前一个表达式至少一次,不限次数
[]= 匹配括号内的任何字符,但只匹配一个
\+\.= 匹配一个文字+.
\w= 另一个单词
-= 匹配一个文字-
*= 匹配前面的表达式零次或无限次
@= 匹配一个文字@符号
()= 将括号内的所有内容
[]设为一个组(并使它们可引用)= 另一个字符集
\w-= 匹配任何单词或一个文字-
+= 另一个1 to infinity量词
\.= 匹配另一个文字.
*= 另一个0 to infinity量词
\w+= 至少匹配一个单词一次
[\w-]*\.= 匹配一个单词或破折号至少零次,然后是文字.
()= 另一个组
[a-z]{2,4}= 匹配小写字母至少 2 次但不超过 4 次
|= "or"(不匹配管道)
\d+=至少1个位数匹配
$=所述字符串的末尾
/=结束的表达式
i=测试中的情况下的串nsensitive方式

Or you could try this awesome link. You know, whatever.

或者你可以试试这个很棒的链接。你知道,随便。

回答by Pranay Rana

var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i

is Regulare expression to test email addres.

是正则表达式来测试电子邮件地址。

Read about regurlare expression on wiki :- http://en.wikipedia.org/wiki/Regular_expression

在 wiki 上阅读有关 regurlare 表达式的信息:- http://en.wikipedia.org/wiki/Regular_expression

回答by sushil bharwani

emailfilter.test(e.value)

emailfilter.test(e.value)

emailfilter is a regular expression against which the e.value that you entered in text field is getting tested.

emailfilter 是一个正则表达式,用于测试您在文本字段中输入的 e.value。

If the passes the regex than the email is valid.

如果通过正则表达式,则电子邮件有效。

回答by Ray Toal

There are several sites online that you can type a regex into and get an explanation for in words. One of them is http://www.strfriend.com/.

有几个在线站点,您可以在其中键入正则表达式并获得文字解释。其中之一是http://www.strfriend.com/

EDIT: More viewers here: https://stackoverflow.com/questions/772594/regular-expression-explained-with-words.

编辑:这里有更多观众:https: //stackoverflow.com/questions/772594/regular-expression-explained-with-words

回答by Alexander Beletsky

This code is just checks validity of entered email addresses by given regular expression, if value is not valid - alert is shown to user.

此代码只是通过给定的正则表达式检查输入的电子邮件地址的有效性,如果值无效 - 向用户显示警报。

If you are not really clear with Regualar Expressions, there are tons info on that:

如果您对 Regualar Expressions 不是很清楚,那么这里有很多信息:

http://www.google.com.ua/search?aq=1&oq=regula&sourceid=chrome&ie=UTF-8&q=regular+expression

http://www.google.com.ua/search?aq=1&oq=regula&sourceid=chrome&ie=UTF-8&q=regular+expression

回答by Alnitak

It's a brokentest for valid RFC 5322 e-mail addresses.

这是一个测试有效的RFC 5322的e-mail地址。

It doesn't cope with quoted user parts, internationalised domain names, or TLDs that have more than 4 characters in them (e.g. .museum, .travel).

它不处理引用的用户部分、国际化域名或包含超过 4 个字符的 TLD(例如.museum, .travel)。

At the same time, it incorrectly permits domain name labels that have a leading or trailing -in them.

同时,它错误地允许带有前导或尾随的域名标签-

DON'T USE IT!

不要使用它!