[英]Adding IP Address to Email Validation RegEx
I am using the RegEx "^[_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+[.])*(\\.[a-zA-Z]{2,17})$"
to validate Email but my lead want to validate as per the Microsoft standard. 我正在使用RegEx "^[_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+[.])*(\\.[a-zA-Z]{2,17})$"
以验证电子邮件,但我的潜在客户希望按照Microsoft标准进行验证。 SO i need to follow 所以我需要跟随
http://msdn.microsoft.com/en-us/library/01escwtf(v=vs.100).aspx http://msdn.microsoft.com/en-us/library/01escwtf(v=vs.100).aspx
In that everything working fine as per the standard but still i am facing the issues with 按照标准,一切正常,但是我仍然面临着
Valid: js#internal@proseware.com Valid: j_9@[129.126.118.1] 有效:js#internal@proseware.com有效:j_9 @ [129.126.118.1]
the above mentioned mail ID is still returning as invalid. 上述邮件ID仍返回为无效。 I tried using the regex used in that page 我尝试使用该页面中使用的正则表达式
^(?("")(""[^""]+?""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9]{2,17}))$
but i am getting the error in the server page. 但我在服务器页面中收到错误。 Though I pasted the expression inside the validation Expression it can't able to accept the characters. 尽管我将表达式粘贴到了验证表达式中,但它无法接受字符。
Note : am using ASP.Net validators for validating the email. 注意:正在使用ASP.Net验证程序来验证电子邮件。
To match both of those email addresses in your sample text, I think I would rewrite your expression like this: 为了匹配示例文本中的这两个电子邮件地址,我想我会这样重写您的表达式:
[A-Z0-9._%#+-]+@(?:[A-Z0-9.-]+\\.[AZ]{2,4}|\\[(?:(?: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]?)\\])
If you're looking to use this to validate a string which may contain only an email then you can add the start/end of string anchors ^
and $
. 如果您希望使用它来验证仅包含电子邮件的字符串,则可以添加字符串锚点^
和$
的开始/结尾。
Sample Text 示范文本
Valid: js#internal@proseware.com Valid: j_9@[129.126.118.1]
Matches 火柴
[0][0] = js#internal@proseware.com
[1][0] = j_9@[129.126.118.1]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.