简体   繁体   English

正则表达式模式匹配排除

[英]Regex pattern match exclude

I would like to match if an email address has invalid TLD. 如果电子邮件地址包含无效的TLD,我想进行匹配。

I have the following regex: 我有以下正则表达式:

/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i

It will match test@test.couk 它将匹配test@test.couk

The value 'couk' is not a valid TLD, how can I edit the above to exclude couk at the end of the email address. 值“ couk”不是有效的TLD,我如何编辑上述内容以排除电子邮件地址末尾的couk。

With regex you can validate only the string's pattern. 使用正则表达式,您只能验证字符串的模式。 It has 2-4 letters, ok - it's valid ! 它有2-4个字母,好的-有效!

To check if TLD is really valid you have to compare it with some TLD database that you have to specify. 要检查TLD是否真的有效,您必须将其与必须指定的某些TLD数据库进行比较。 No other way, sorry ! 没有其他办法,对不起!

您可以尝试使用否定的(?!couk)

^[AZ\\d._%+-]+@[AZ\\d.-]+\\.((?!couk)[AZ]{2,4})$

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM