[英]Restrict particular domain in email regular expression
I have an existing regex which validates the email input field.我有一个现有的正则表达式来验证电子邮件输入字段。
[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!$%&'*+/=?^_`{|}~-]+)*(\\.)?@(?:[a-zA-Z0-9ÄÖÜäöü](?:[a-zA-Z0-9-_ÄÖÜäöü]*[a-zA-Z0-9_ÄÖÜäöü])?\\.)+[a-zA-Z]{2,}
Now, I want this regex to not match for two particular type of email IDs.现在,我希望这个正则表达式不匹配两种特定类型的电子邮件 ID。 Which are wt.com and des.net
哪个是wt.com和des.net
To do that I made the following changes in the above expression like this.为此,我对上述表达式进行了以下更改。
[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!$%&'*+/=?^_`{|}~-]+)*(\\.)?@(?!wt\\.com)(?!des\\.net)(?:[a-zA-Z0-9ÄÖÜäöü](?:[a-zA-Z0-9-_ÄÖÜäöü]*[a-zA-Z0-9_ÄÖÜäöü])?\\.)+[a-zA-Z]{2,}
After this it does not matches with any email id which ends with the wt.com and des.net which is right.在此之后,它与任何以正确的 wt.com 和 des.net 结尾的电子邮件 ID 都不匹配。 But the problem is it does not match with wt.comm or any other letter after the restricted string too.. I just want to restrict email which ends with wt.com and des.net How do I do that?
但问题是它与 wt.comm 或受限字符串后的任何其他字母都不匹配..我只想限制以wt.com和des.net结尾的电子邮件我该怎么做? Below is the sample emails which should match or not.
以下是应该匹配或不匹配的示例电子邮件。
If you want to prevent only wt.com
and des.net
which have no characters after it you can add $
anchor (which represents end of string) at the end of each negative-look-ahead.如果您只想阻止
wt.com
没有字符的wt.com
和des.net
,您可以在每个否定wt.com
des.net
添加$
锚点(代表字符串的结尾)。
So instead of (?!wt\\\\.com)(?!des\\\\.net)
use (?!wt\\\\.com$)(?!des\\\\.net$)
所以代替
(?!wt\\\\.com)(?!des\\\\.net)
使用(?!wt\\\\.com$)(?!des\\\\.net$)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.